Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

My Class Model
C#
Public Class Channel
{
   public int ChannelId {get;set;}
   public string ChannelName {getlset;}
   public string ChannelCode {get;set;}
}

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.
Posted
Updated 5-Aug-14 1:26am
v2

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?
 
Share this answer
 
Comments
Manoj B. Kalla 5-Aug-14 8:41am    
Dear Dave,

I want to add a new property like

public string ChannelArea {get;set;}

and want used in EDIT view only.

For this I want to create a new model again. But I want to add new property runtime. For this what should I do.
Dave Kreskowiak 5-Aug-14 12:43pm    
I think you REALLY need to pickup a book on MVC and work through it.

You NEVER modify your Model classes just to pass them to the View. You create ViewModel classes that take the information from the Model classes and any additional data the View may need to display/edit the data.
Manoj B. Kalla 6-Aug-14 3:25am    
Dear Dave Kreskowiak sir,

I searched and got my answer.

Thanks for your answers.

http://stackoverflow.com/questions/14447297/asp-net-mvc-4-how-to-access-modify-the-view-model-object-and-change-view-and-a
Dave Kreskowiak 6-Aug-14 8:25am    
Yeah, about that. Either you've not explained your requirement in enough detail or you're going about this the hard way and will find that it is indeed not the solution you're looking for.

Good luck.
Dear Dave Kreskowiak sir,

I searched and got my answer.

Thanks for your answers.

Answer as per my requirement
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900