У меня есть mvc, и мне нужно отобразить значения из модели в представлении после того, как пользователь заполнил некоторые параметры формы. Когда я помещаю точку останова в код, модель содержит правильные значения из формы, однако когда я пытаюсь отобразить ее, она не работает. Вот моя форма и вверху у меня есть тестовый заголовок, в котором я пытаюсь отобразить одно из значений, которые мне нужно отобразить в представлении.
@using SharedComponents
@model FIAECBC
@{
ViewBag.Title = "CBC";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Styles.Render("~/Content/FormStyle.css")
<main id="main" style="background-color:deeppink; background-repeat:no-repeat; background-size:cover;">
<!-- ======= Describe Section ======= -->
<section class="section section-describe">
<div class="container" style="margin-top: 150px;">
<div class="row">
<h3></h3>
<h1 style="color:black">composite val: @Html.DisplayFor(model => model.Neutrophils)</h1>
<div class="col-md-4" data-aos="fade-up">
<h2>Engine Test</h2>
@using (Html.BeginForm("CBC", "FIAE", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="field" tabindex="1">
<label for="name" style="color:white">
<i class="far fa-user"></i>Your Username
</label>
<input type="text" style="color: darkgray" name="username" placeholder="e.g. Adam Smith" required />
</div>
<div class="field" tabindex="2">
<label for="email" style="color:white">
<i class="far fa-envelope"></i>
Email:
</label>
<input type="email" style="color:darkgray" name="email" placeholder="email@domain.com" required />
</div>
<label>
Select Biological Gender: <br />
</label>
@Html.DropDownListFor(m => m.UserGender, FIAECBC.GetSelectItems(), new { @class = "dropitdown" })
<br />
<div class="field" tabindex="3">
<label for="platelets" style="color:white">
<i class="far fa-user"></i>Platelets
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Platelets" placeholder="160" required /> x10^3/mm^3
</div>
<br />
<div class="field" tabindex="4">
<label for="MCH" style="color:white">
<i class="far fa-user"></i>MCH
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="MCH" placeholder="30" required /> pg
</div>
<div class="field" tabindex="4">
<label for="MCV" style="color:white">
<i class="far fa-user"></i>MCV
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="MCV" placeholder="85" required /> u^3
</div>
<div class="field" tabindex="4">
<label for="Neutrolphils" style="color:white">
<i class="far fa-user"></i>Neutrolphils
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Neutrophils" placeholder="85" required />%
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>MCHC
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="MCHC" placeholder="85" required /> g/dl
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>Lympthocytes
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Lympthocytes" placeholder="85" required />%
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>Monocytes
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Monocytes" placeholder="85" required />%
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>Eosinophils
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Eosinophils" placeholder="85" required />%
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>Haemoglobin
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Haemoglobin" placeholder="85" required /> g/dl
</div>
<div class="field" tabindex="4">
<label for="MCHC" style="color:white">
<i class="far fa-user"></i>Haematocrit
</label>
<br />
<input type="number" step="0.01" style="color: darkgray" name="Haematocrit" placeholder="85" required /> %
</div>
<button type="submit" id="submit" style="background-color:black" onchange="">Submit</button>
<br />
}
</div>
<div class="col-md-6">
</div>
</div>
</div>
</section>
</main><!-- End #main -->
Это внешний класс, в котором я выполняю некоторые logi c и манипуляции с данными, прежде чем я отправлю их в модель:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharedComponents;
using static SharedComponents.FIAECBC;
namespace FIAE
{
public class FIAEngine
{
decimal d_Neutrophils;
decimal d_Lymphocytes;
decimal d_Monocytes;
decimal d_Eosinophils;
decimal d_Platelets;
decimal d_Haematocrit;
decimal d_Haemoglobin;
decimal d_MCV;
decimal d_MCH;
decimal d_MCHC;
string UserID;
string Gender;
string Neutrophils;
string Lymphocytes;
string Monocytes;
string Eosinophils;
string Platelets;
string Haematocrit;
string Haemoglobin;
string MCV;
string MCH;
string MCHC;
string NeutrophilRAG;
string LymphocytesRAG;
string MonocytesRAG;
string EosinophilsRAG;
string PlateletsRAG;
string HaematocritRAG;
string HaemoglobinRAG;
string MCVRAG;
string MCHRAG;
string MCHCRAG;
public void setcbcvals(decimal[] inputs, string _UserID, string _Gender)
{
d_Neutrophils = inputs[0];
d_Lymphocytes = inputs[1];
d_Monocytes = inputs[2];
d_Eosinophils = inputs[3];
d_Platelets = inputs[4];
d_Haematocrit = inputs[5];
d_Haemoglobin = inputs[6];
d_MCV = inputs[7];
d_MCH = inputs[8];
d_MCHC = inputs[9];
UserID = _UserID;
Gender = _Gender;
Neutrophils = "Neutrophils";
Lymphocytes = "Lymphocytes";
Monocytes = "Monocytes";
Eosinophils = "Eosinophils";
Platelets = "Platelets";
Haematocrit = "Haematocrit";
Haemoglobin = "Haemoglobin";
MCV = "MCV";
MCH = "MCH";
MCHC = "MCHC";
NeutrophilRAG = "i";
LymphocytesRAG = "i";
MonocytesRAG = "i";
EosinophilsRAG = "i";
PlateletsRAG = "i";
HaematocritRAG = "i";
HaemoglobinRAG = "i";
MCVRAG = "i";
MCHRAG = "i";
MCHCRAG = "i";
try
{
//male calculations
if (Gender == "Male")
{
NeutrophilRAG = FindMaleRAG(d_Neutrophils, 1);
LymphocytesRAG = FindMaleRAG(d_Lymphocytes, 2);
MonocytesRAG = FindMaleRAG(d_Monocytes, 3);
EosinophilsRAG = FindMaleRAG(d_Eosinophils, 4);
PlateletsRAG = FindMaleRAG(d_Platelets, 5);
HaematocritRAG = FindMaleRAG(d_Haematocrit, 6);
HaemoglobinRAG = FindMaleRAG(d_Haemoglobin, 7);
MCVRAG = FindMaleRAG(d_MCV, 8);
MCHRAG = FindMaleRAG(d_MCH, 9);
MCHCRAG = FindMaleRAG(d_MCHC, 10);
//set view model values to the form values
var cbcmodel = new FIAECBC
{
d_Neutrophils = d_Neutrophils,
d_Lymphocytes = d_Lymphocytes,
d_Monocytes = d_Monocytes,
d_Eosinophils = d_Eosinophils,
d_Platelets = d_Platelets,
d_Haematocrit = d_Haematocrit,
d_Haemoglobin = d_Haemoglobin,
d_MCV = d_MCV,
d_MCH = d_MCH,
d_MCHC = d_MCHC,
Neutrophils = Neutrophils,
Lymphocytes = Lymphocytes,
Monocytes = Monocytes,
Eosinophils = Eosinophils,
Platelets = Platelets,
Haematocrit = Haematocrit,
Haemoglobin = Haemoglobin,
MCV = MCV,
MCH = MCH,
MCHC = MCHC,
rag_Neutrophils = NeutrophilRAG,
rag_Lymphocytes = LymphocytesRAG,
rag_Monocytes = MonocytesRAG,
rag_Eosinophils = EosinophilsRAG,
rag_Platelets = PlateletsRAG,
rag_Haematocrit = HaematocritRAG,
rag_Haemoglobin = HaemoglobinRAG,
rag_MCV = MCVRAG,
rag_MCH = MCHRAG,
rag_MCHC = MCHCRAG,
};
string me = "9";
}
else if (Gender == "Female")
{
NeutrophilRAG = FindfeMaleRAG(d_Neutrophils, 1);
LymphocytesRAG = FindfeMaleRAG(d_Lymphocytes, 2);
MonocytesRAG = FindfeMaleRAG(d_Monocytes, 3);
EosinophilsRAG = FindfeMaleRAG(d_Eosinophils, 4);
PlateletsRAG = FindfeMaleRAG(d_Platelets, 5);
HaematocritRAG = FindfeMaleRAG(d_Haematocrit, 6);
HaemoglobinRAG = FindfeMaleRAG(d_Haemoglobin, 7);
MCVRAG = FindfeMaleRAG(d_MCV, 8);
MCHRAG = FindfeMaleRAG(d_MCH, 9);
MCHCRAG = FindfeMaleRAG(d_MCHC, 10);
//set view model values to the form values
var cbcmodel = new FIAECBC
{
d_Neutrophils = d_Neutrophils,
d_Lymphocytes = d_Lymphocytes,
d_Monocytes = d_Monocytes,
d_Eosinophils = d_Eosinophils,
d_Platelets = d_Platelets,
d_Haematocrit = d_Haematocrit,
d_Haemoglobin = d_Haemoglobin,
d_MCV = d_MCV,
d_MCH = d_MCH,
d_MCHC = d_MCHC,
Neutrophils = Neutrophils,
Lymphocytes = Lymphocytes,
Monocytes = Monocytes,
Eosinophils = Eosinophils,
Platelets = Platelets,
Haematocrit = Haematocrit,
Haemoglobin = Haemoglobin,
MCV = MCV,
MCH = MCH,
MCHC = MCHC,
rag_Neutrophils = NeutrophilRAG,
rag_Lymphocytes = LymphocytesRAG,
rag_Monocytes = MonocytesRAG,
rag_Eosinophils = EosinophilsRAG,
rag_Platelets = PlateletsRAG,
rag_Haematocrit = HaematocritRAG,
rag_Haemoglobin = HaemoglobinRAG,
rag_MCV = MCVRAG,
rag_MCH = MCHRAG,
rag_MCHC = MCHCRAG,
};
}
}
catch
{
}
string po = "op9";
//return inputs;
}
public string FindMaleRAG(decimal i, int x)
{
String connString = Convert.ToString(ConfigurationManager.ConnectionStrings["SQLServerCon"]);
//for each row, do this
//find the threshld values
String thresholdquery = @"select * from dbo.malethreshold where ID = " + x;
using (var conn = new SqlConnection(connString))
{
conn.Open();
using (SqlCommand command = new SqlCommand(thresholdquery, conn))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
//compare threshold values t posted values from form
string composite = Convert.ToString(reader[1]);
decimal redlow = Convert.ToDecimal(reader[2]);
decimal greenlow = Convert.ToDecimal(reader[3]);
decimal greenhigh = Convert.ToDecimal(reader[4]);
decimal redhigh = Convert.ToDecimal(reader[5]);
if (i < redlow)
{
// Red low
return ("Red Low");
}
else if (i > redlow && i < greenlow)
{
// Amber Low
return ("Amber Low");
}
else if (i >= greenlow && i <= greenhigh)
{
//green
return ("Green");
}
else if (i > greenhigh && i < redhigh)
{
//amber high
return ("Amber High");
}
else if (i > redhigh)
{
// Redhigh
return ("Red High");
}
else
{
//sorting error
return ("error in sorting");
}
}
}
}
}
return ("sorting error");
}
public string FindfeMaleRAG(decimal i, int x)
{
String connString = Convert.ToString(ConfigurationManager.ConnectionStrings["SQLServerCon"]);
//for each row, do this
//find the threshld values
String thresholdquery = @"select * from dbo.malethreshold where ID = " + x;
using (var conn = new SqlConnection(connString))
{
conn.Open();
using (SqlCommand command = new SqlCommand(thresholdquery, conn))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
//compare threshold values t posted values from form
string composite = Convert.ToString(reader[1]);
decimal redlow = Convert.ToDecimal(reader[2]);
decimal greenlow = Convert.ToDecimal(reader[3]);
decimal greenhigh = Convert.ToDecimal(reader[4]);
decimal redhigh = Convert.ToDecimal(reader[5]);
if (i < redlow)
{
// Red low
return ("Red Low");
}
else if (i > redlow && i < greenlow)
{
// Amber Low
return ("Amber Low");
}
else if (i >= greenlow && i <= greenhigh)
{
//green
return ("Green");
}
else if (i > greenhigh && i < redhigh)
{
//amber high
return ("Amber High");
}
else if (i > redhigh)
{
// Redhigh
return ("Red High");
}
else
{
//sorting error
return ("error in sorting");
}
}
}
}
}
return ("sorting error");
}
}
}
Затем, наконец, вот моя модель, которая содержит все значения, которые мне нужно отобразить, а также раскрывающийся список для посмотреть
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace SharedComponents
{
public class FIAECBC
{
public string Neutrophils { get; set; }
public string Lymphocytes { get; set; }
public string Monocytes { get; set; }
public string Eosinophils { get; set; }
public string Platelets { get; set; }
public string Haematocrit { get; set; }
public string Haemoglobin { get; set; }
public string MCV { get; set; }
public string MCH { get; set; }
public string MCHC { get; set; }
public decimal d_Neutrophils { get; set; }
public decimal d_Lymphocytes { get; set; }
public decimal d_Monocytes { get; set; }
public decimal d_Eosinophils { get; set; }
public decimal d_Platelets { get; set; }
public decimal d_Haematocrit { get; set; }
public decimal d_Haemoglobin { get; set; }
public decimal d_MCV { get; set; }
public decimal d_MCH { get; set; }
public decimal d_MCHC { get; set; }
public string rag_Neutrophils { get; set; }
public string rag_Lymphocytes { get; set; }
public string rag_Monocytes { get; set; }
public string rag_Eosinophils { get; set; }
public string rag_Platelets { get; set; }
public string rag_Haematocrit { get; set; }
public string rag_Haemoglobin { get; set; }
public string rag_MCV { get; set; }
public string rag_MCH { get; set; }
public string rag_MCHC { get; set; }
public Gender UserGender { get; set; }
public static IEnumerable<SelectListItem> GetSelectItems()
{
yield return new SelectListItem { Text = "Male", Value = "Male" };
yield return new SelectListItem { Text = "Female", Value = "Female" };
}
public bool Bookkeeping { get; set; }
}
public enum Gender
{
Male,
Female
}
}