这很愚蠢,但我不知道该怎么做。我有以下类图:
模型:
public class TKKService
{
public string Name = string.Empty;
public TKKService() {}
}
控制器:
public class ServiceController : Controller
{
public ActionResult Index()
{
return View(new TKKService());
}
[HttpPost]
public ActionResult Index(TKKService Mod)
{
TKKService serv = new TKKService();
if (ModelState.IsValid)
{
serv.Name = Mod.Name + "_next";
}
return View(serv);
}
}
看法:
@model TKK_Portal.Models.TKKService
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm())
{
@Model.Name
@Html.EditorFor(model=>model.Name)
<input type="submit" value="Wyslij"/>
}
执行Submit
方法时,Model.Name
不包含已编辑的数据。它采用默认值Empty
。