asp.net mvc - RemoteAttribute is not passing parameter to action? -


i trying use remoteattribute validate data element serverside using json. data field is:

[display(name = "my number")]     [required]     [remote("isvalidmynumber","home",errormessage="bummer")]     public string mynumber { get; set; } 

my controller is:

  public jsonresult isvalidmynumber(string mynumber)     {         var test = services.validatemynumber(mynumber);         return json(test,jsonrequestbehavior.allowget);     } 

my view is:

    <div class="editor-field">     @html.editorfor(model => model.checkinformation.mynumber)      @html.validationmessagefor(model => model.checkinformation.mynumber) </div> 

the html generated is:

 <input class="text-box single-line" data-val="true" data-val-remote="bummer"  data-val-remote-additionalfields="*.mynumber" data-val-remote-url="/home/isvalidmynumber"  data-val-required="the number field required." id="checkinformation_mynumber"  name="checkinformation.mynumber" type="text" value="" /> 

when debug , step inside controller "mynumber" parameter null though have text in textbox represents.

i know name has same in textbox in parameter , have validated that.

any ideas?

seems generated name of input field is:

name="checkinformation.mynumber" 

that's because view model parent model of have shown in question , used along lines of:

@html.textboxfor(x => x.checkinformation.mynumber) 

so make sure have specified prefix or default model binder never able rehydrate values:

public actionresult isvalidmynumber([bind(prefix = "checkinformation")] string mynumber) {     var test = services.validatemynumber(mynumber);     return json(test, jsonrequestbehavior.allowget); } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -