[英]How to add a HtmlPrefix to Views Using MVC Actions?
I have the following action to call the Multiple partial Views in a Single page. 我有以下操作来在单个页面中调用多个局部视图。
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)
The above code gives me the html rendered as 上面的代码给了我html呈现为
<input type="text" name="Name"/>
But, I wants to have 但是,我想要
<input type="text" name="Customer.Name" />
If I pass the AddDetail("Customer")
action. 如果我通过
AddDetail("Customer")
动作。
I don't know how to get the ViewContext
and append the Prefix
to the Views. 我不知道如何获取
ViewContext
并将Prefix
到视图。
Could someone please help me to add a prefix? 有人可以帮我添加前缀吗?
Try this :) 尝试这个 :)
public ActionResult AddDetail(string Key)
{
ViewData.TemplateInfo.HtmlFieldPrefix = string.Format("{0}", key)
return View(key);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.