【发布时间】:2015-06-17 10:57:42
【问题描述】:
发生了一些奇怪的事情,我无法理解为什么......这是场景 -
当我填充模型时,我有一个属性很少的模型,模型中的属性确实设置了值(通过放置断点进行检查)。它也出现在视图上,但没有显示在文本框中。它显示默认值(通过查看页面上的项目文本框来猜测,因为它有 0)。
下面是我的模型-
public class PriceEnquiryModel
{
[DisplayName("Item")]
public int item { get; set; }
[DisplayName("Description")]
public string description { get; set; }
[DisplayName("UOP")]
public string uop { get; set; }
[DisplayName("UOS")]
public string uos { get; set; }
[DisplayName("Pack Description")]
public string pack_description { get; set; }
[DisplayName("Pack Size")]
public string PackSize { get; set; }
}
这是控制器的代码 -
public ActionResult Search(PriceEnquiryModel price)
{
var priceEnquiryModel = new PriceEnquiryModel();
// Read parameter values from form.
int item = Convert.ToInt32(Request.Form["txtSearch"].ToString());
int maxrow = Convert.ToInt32(Request.Form["txtmaxrow"].ToString());
string priceType = !string.IsNullOrWhiteSpace(price.priceType) && price.priceType.ToUpper().Equals("STA") ? "N" : "Y";
// Get the price information
var operationResult = priceBal.SearchPriceEnquiry(0, item, price.price_scheme, priceType, maxrow);
var priceEnquiryDomList = (List<PriceEnquiryDom>)operationResult[0].Result;
// Check if we have something
if (priceEnquiryDomList != null && priceEnquiryDomList.Count > 0)
{
// Parse the model.
priceEnquiryModel = helper.ConvertDomToModel(priceEnquiryDomList[0]);
// Prepare the list.
priceEnquiryModel.PriceEnquiryModelList = new List<PriceEnquiryModel>();
foreach (var priceEnquiryDom in priceEnquiryDomList)
{
var priceEnquiryModelListItem = helper.ConvertDomToModel(priceEnquiryDom);
priceEnquiryModel.PriceEnquiryModelList.Add(priceEnquiryModelListItem);
}
Session["mainModel"] = priceEnquiryModel;
}
// Prepare product drop down list items if searched by product desc
if (TempData.Count > 0 && TempData["Products"] != null)
{
var products = TempData["Products"] as List<ProductSearchByDescModel>;
ViewBag.Products = products;
}
return View("Index", priceEnquiryModel);
}
这是视图上的模型(调试时)-
这就是我在视图上渲染模型的方式 -
这是运行后的页面-
有人知道发生了什么吗?我在多个页面上做了同样的事情,并且都按预期运行。
提前致谢。 罗希特
【问题讨论】:
-
你能告诉我们行动吗?当您将模型操作传递给视图时,可能会发生一些问题。
-
是否有任何 JavaScript 混淆了这些值?
-
@beautifulcoder,没有这样的js..
-
@MahediSabuj - 在渲染时的视图中,它具有模型中的值。它只是没有显示在页面上。看第二张图片,它确实有值。
-
你需要展示你的控制器方法。您的 GET 方法在签名中有参数
PriceEnquiryModel吗?通过在视图中添加<div>@Model.description</div>来进行测试以检查其是否正确 - 如果是,则为ModelState问题。
标签: c# asp.net-mvc