如何在mvc4中动态添加新的模型属性? [英] How to add a new model property dynamically in mvc4?
本文介绍了如何在mvc4中动态添加新的模型属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
我的班级模特
Dear Friends,
My Class Model
Public Class Channel
{
public int ChannelId {get;set;}
public string ChannelName {getlset;}
public string ChannelCode {get;set;}
}
创建方法时运行,我通过做名为ChannelId的无声属性
ModelState.Remove(ChannelId);
Somewhare我想再次添加 ChannelId 或任何属性我该怎么办?
甚至,我知道。 。这个命令。
ModelState.Add(...)但不能正常工作。 。
请。 。指导我。
While create method run, I silent property named ChannelId by doing
ModelState.Remove("ChannelId");
Somewhare I want to add again ChannelId or any property what should I do?
Even, I know. . this command.
ModelState.Add(...) but not working. .
Please. . Guide me.
推荐答案
您无法动态修改模型,因为这还需要修改基础数据存储,可能会破坏流程中的信息。
真的没有理由这么做,所以你真的想用这个做什么?
You cannot modify the model dynamically since this would also require modifying the underlying data store, possibly destroying information in the process.
There really isn't a good reason to do this so what are you really trying to do with this?
亲爱的Dave Kreskowiak先生,
我搜索并得到了答案。
感谢您的回答。< br $> b $ b
根据我的要求回答
这篇关于如何在mvc4中动态添加新的模型属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文