我有以下操作来调用单页中的多个部分视图。
public ActionResult AddDetail(string Key)
{
var viewData = new ViewDataDictionary(ViewData)
{
TemplateInfo = new System.Web.Mvc.TemplateInfo
{
HtmlFieldPrefix = string.Format("{0}", key)
}
};
return View(key);
}
[View]
@model Customer
@Html.TextBoxFor(model=>model.Name)
上面的代码为我提供了呈现为
的html<input type="text" name="Name"/>
但是,我想要
<input type="text" name="Customer.Name" />
如果我通过AddDetail("Customer")
操作。
我不知道如何获取ViewContext
并将Prefix
附加到视图中。
有人可以帮我添加前缀吗?
答案 0 :(得分:3)
试试这个:)
public ActionResult AddDetail(string Key)
{
ViewData.TemplateInfo.HtmlFieldPrefix = string.Format("{0}", key)
return View(key);
}