Remove prefix from posted data in asp.net mvc -
i have view looks below. each field has prefix attached in name property, model in backend has property without prefix.
@using (html.beginform("save", "home", formmethod.post)) { @html.validationsummary(true) <fieldset> <input type="hidden" name="prefix" value="prefix"/> <input type="text" id="prefix.name" name="prefix.name"/> <input type="submit" value="submit" /> </fieldset> }
my action method looks below :
public actionresult save([modelbinder(typeof(custommodelbinder))]employee employee) { throw new notimplementedexception(); }
my model looks :
public class employee { public string name { get; set; } }
can me how achieve through custom model binder, want strip prefix each of posted form items name.
posted form data :
prefix:prefix prefix.name:hello world!!
i tried below code it's not working. can explain whats wrong here.
public actionresult save([bind(prefix = "prefix")]employee employee) { throw new notimplementedexception(); }
try adding binding prefix value, this:
public actionresult setpassword([bind(prefix = "form")] usersetpasswordform form) { if (!modelstate.isvalid) { .... } ... }
Comments
Post a Comment