asp.net-mvc-3 – ASP.MVC 3 Razor在Html.PartialView扩展中添加模型前缀
发布时间:2020-05-23 21:09:42 所属栏目:asp.Net 来源:互联网
导读:我和他的问题大致相同 ASP.NET MVC partial views: input name prefixes 我想为这些数据实体创建CRUD操作: public class UserViewModel { protected virtual Id {get; set;} public virtual string Login { get; set; } public
|
我和他的问题大致相同 ASP.NET MVC partial views: input name prefixes 我想为这些数据实体创建CRUD操作: public class UserViewModel
{
protected virtual Id {get; set;}
public virtual string Login { get; set; }
public virtual string Password { get; set; }
public virtual ZipCodeViewModel ZipCode { get; set; }
}
邮政编码实体: public class ZipCodeViewModel
{
public virtual string City { get; set; }
public virtual string State { get; set; }
public virtual string Zip { get; set; }
}
我也有部分视图ZipCode使用UserViewModel.ZipCode: @model ZipCodeViewModel
@Html.TextBoxFor(x => x.Zip,new { id = "ZipCode",name = "ZipCode.Zip",maxlength = "5" })
我将在另一个页面(例如用户)中使用ZipCodePartialView. @model UserViewModel
.....
@{Html.RenderPartial("Zipcode",Model.ZipCode);}
当MVC保存用户ZipCode字段Zip为空时. 那么问题是我如何为patrial View添加模型前缀? 解决方法试试这个扩展:public static void RenderPartialWithPrefix(this HtmlHelper helper,string partialViewName,object model,string prefix)
{
helper.RenderPartial(partialViewName,model,new ViewDataDictionary { TemplateInfo = new System.Web.Mvc.TemplateInfo { HtmlFieldPrefix = prefix } });
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 将ViewData传递给RenderPartial
- asp.net-mvc-2 – 如何在局部视图中获取与父操作关联的Rout
- asp.net-mvc-3 – mvc3 httpshttp
- asp.net-mvc – MVC Ajax.BeginForm替换奇怪的行为
- .net – 如何在MVC 5中设置本地授权认证?
- asp.net-core – compilationOptions.emitEntryPoint是什么
- asp.net-mvc-3 – 检查.NET MVC中的AngularJS $资源请求服务
- asp.net-mvc – 用Moq Mocking HttpContextBase
- asp.net – App Settings和connectionStrings配置设置中连接
- ASP.NET OutputCache和Cookies
推荐文章
站长推荐
- asp.net-mvc – 在表单提交时传递整个模型
- asp.net-mvc – 如何手动创建简单的成员资格sql表
- asp.net-mvc – 将DTO转换为ViewModel的位置?
- asp.net – “HttpContext.Current”属性和相关事
- asp.net – 在应用程序级别之外注册为allowDefin
- asp.net – 在用户控件中关闭页面级缓存
- 如何在ServiceStack服务实现中使用标准的ASP.NET
- asp.net-mvc – 是否有一个用于ASP.NET MVC的玉模
- asp.net – Windows Azure我可以在同一个额外的小
- asp.net – 为什么aspx代码隐藏文件被声明为部分
热点阅读
