MVC中 .netFramwork到view 跟 view到action
MVC中 .netFramwork到view 和 view到action
Model:
Controler:
view:
结果:
<td>
<input name="workitem.Title" id="workitem_Title" style="width: 800px;" type="text" value="" data-val-required="Title 字段是必需的。" data-val="true"></td>
问题:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateWorkItem workitem)
这个函数获取不到数据。
估计name如果是workitem.workitem.Title,才能获取到数据。
各位有什么办法帮我获取到数据吗?
------解决思路----------------------
直接 using beginform 使用 post提交 ,按钮时 submit可以吗?
Model:
public class CreateWorkItem
{
public CreateWorkItem()
{
this.linkList = new List<Links>();
this.workitem = new workItem();
}
public List<Links> linkList { get; set; }
public workItem workitem { get; set; }
}
Controler:
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateWorkItem workitem)
{
if (ModelState.IsValid)
{
db.workItem.Add(workitem.workitem);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(workitem);
}
view:
@model SoftWareTrackingWebSite.Models.CreateWorkItem
...
<td> @Html.TextBoxFor(model => model.workitem.Title, new { style = "width:800px;" })</td>
...
结果:
<td>
<input name="workitem.Title" id="workitem_Title" style="width: 800px;" type="text" value="" data-val-required="Title 字段是必需的。" data-val="true"></td>
问题:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateWorkItem workitem)
这个函数获取不到数据。
估计name如果是workitem.workitem.Title,才能获取到数据。
各位有什么办法帮我获取到数据吗?
------解决思路----------------------
直接 using beginform 使用 post提交 ,按钮时 submit可以吗?