绑定排除不工作模型绑定在ASP.Net MVC的子对象 [英] Bind Exclude not working Model Binding for child objects in ASP.Net MVC
问题描述
我钻进模型Asp.Net MVC绑定问题。我有视图模型如下图所示,
I got into a issue in Model Binding in Asp.Net MVC. I have view model like below,
public class ArticleViewModel : BaseViewModel
{
public Article art { get; set; }
public List<ArticleAttachment> attachments { get; set; }
}
我试图排除模型中的条子对象绑定属性在我的操作方法如下所示,
I am trying to exclude model binding a property on the "Article" child object as seen below in my action method,
[HttpPost]
[ValidateInput(false)]
public ActionResult New([Bind(Exclude = "art.Abstract")]ArticleViewModel articleVM)
{
但模型绑定填充叫做抽象的财产,即使上面的设置。
But the model binder populates the property called Abstract even with the above setting.
请让我知道,如果我做错什么。我需要排除一些在文章子对象的属性做模型绑定时。
Please let me know if i am doing anything wrong. I need to exclude some of the properties in the Article child object when doing Model binding.
推荐答案
嘿,我对面的同样的问题绊倒。是否有仍然没有解决方案?
Hey I just stumbled across the same issue. Is there still no solution for that?
我现在的解决方法是innitialize的childobject并设置可忽略不计为有效值(在我的情况下,它是将被innitially设置为-1整数属性),这部作品的属性,但我宁愿prefere正常绑定(不含)解决方案。
My workaround right now is to innitialize the childobject and set the property that shall be ignored to a valid value (in my case it is an integer property which will be innitially set to -1) this works, but I'd rather prefere the normal Bind(Exclude) solution.
这篇关于绑定排除不工作模型绑定在ASP.Net MVC的子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!