传递给视图的模型未填充输入(Inputs Not Being Populated By Model Passed to View)

编程入门 行业动态 更新时间:2024-10-23 04:51:33
传递给视图的模型未填充输入(Inputs Not Being Populated By Model Passed to View)

我有一个视图,并将视图模型传递给它,以填充强类型输入。 视图模型创建得很好。 我调试了控制器以确保正确创建模型,并使用数据库(SQL Management Server 2008)中的正确值设置视图模型的属性,它正在执行此操作没有问题。 当我将视图模型传递到视图中时,只会填充一些强类型输入,而其他输入则不会。 我已经检查过以确保我的所有输入都指向正确的模型参数。 该表单由6个页面组成,我正在使用Kendo UI TabStrip来保持页面分离。 视图模型相当大,所以我想知道这是否是一个因素。 基本功能是用户可以开始填写表单,将其保存到数据库,检索他们填写的内容,然后在以后完成。 以下是一些示例代码:

以下是视图的代码段:

@model myWilmer.Models.QuoteViewModel <section id="quoteEntry"> @Html.ValidationSummary(true) @using (Html.BeginForm("CreateQuote", "Quotes", FormMethod.Post, new { id = "quotesForm" })) { @Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", Value = "", id = "quoteNumber"}) }

以下是视图模型的片段:

public class QuoteViewModel { public QuoteViewModel() { } [Display(Name = "Quote Number:")] [Required] [RegularExpression(@"^[0-9]+$")] public int QuoteNum { get; set; } }

这是控制器的片段:

[HttpGet] public ActionResult Edit(int id) { QuoteViewModel qvm; //...Creating ViewModel return View(qvm); }

I have a view and am passing a view model to it in order to populate the strongly typed inputs. The view model is created just fine. I have debugged the controller to ensure that model is created properly and the properties of the view model are set with the correct values from the database (SQL Management Server 2008), which it is doing with no problem. When I pass the view model into the view, only some of the strongly typed inputs are populated and the others aren't. I've checked to make sure that I have all of the inputs are pointing to the correct model parameter. The form consists of 6 pages that I'm using Kendo UI TabStrip to keep the pages separate. The view model is fairly large so I'm wondering if that is a factor. The basic functionality is that a user can start filling out a form, save it to the db, retrieve what they have filled out, and then complete it at a later date. Here is some sample code:

Here is a code snippet of the view:

@model myWilmer.Models.QuoteViewModel <section id="quoteEntry"> @Html.ValidationSummary(true) @using (Html.BeginForm("CreateQuote", "Quotes", FormMethod.Post, new { id = "quotesForm" })) { @Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", Value = "", id = "quoteNumber"}) }

Here is a snippet of the view model:

public class QuoteViewModel { public QuoteViewModel() { } [Display(Name = "Quote Number:")] [Required] [RegularExpression(@"^[0-9]+$")] public int QuoteNum { get; set; } }

Here is a snippet of the controller:

[HttpGet] public ActionResult Edit(int id) { QuoteViewModel qvm; //...Creating ViewModel return View(qvm); }

最满意答案

您通过使用Value =“”来覆盖Value。 删除它,它应该工作。

@Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", id = "quoteNumber"})

You are overriding the Value by having Value = "". Remove that and it should work.

@Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", id = "quoteNumber"})

更多推荐

本文发布于:2023-08-01 04:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1353867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   模型   Inputs   Populated   Passed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!