c# - How can I rename parameter in action -
i have action:
public jsonresult isawesome(string value){...}
but in form parameter looks "viewmodelname.somepropvalue" , cant alter there. how create work value 'viewmodelname.somepropvalue' in 'value' action parameter.
for example:
<input name="viewmodelname.somepropvalue" value="mydata" /> public jsonresult isawesome(string value){ value=="mydata"; }
one way utilize formmodel
class model binder can bind each property.. in case form take viewmodel input
class viewmodel { public formmodel formmodel{get;set;} } public class formmodel { public string somepropvalue{get;set;} } public void action(viewmodel formviewmodel)
another option utilize partial view.
in view taking viewmodel, render partial:
@html.renderpartial("form",model.formmodel)
in rendered patial view:
@html.editorfor(model=>model.somepropvalue);
which means action can take formmodel
object:
public void action(formmodel formmodel)
c# asp.net-mvc
No comments:
Post a Comment