jquery - Bind an element in two forms -


im using aspnet mvc 5 develop web app , have typed view 2 forms, second 1 showed when first 1 submited ( via ajax ):

 @model dto.userdto   <form id="firstform">           @html.editorfor(model => model.name) //need property on both forms, in second form readonly input value.     @html.validationmessagefor(model => model.name, string.empty})     <button type="submit" id="btnsearchname"></button>   </form>   //second form   @using (html.beginform())   {       //other inputs other properties in userdto viewmodel        <input type="submit" class="btn btn-success btn-lg" value="save" />   }    <script>     $("#firstform").submit(function (e) {             e.preventdefault();             if (!$(this).valid()) {                 return false;             }             findname(); //ajax request             return true; // if true, expand(show) second form         });   </script> 

on controller action second form:

    [httppost]     public actionresult save([bind(exclude = "id")]userdto model)     {          //the modelstate fails here because name within required attribute , on first form.              } 

so, problem need pass name property save action within actual value user input on first form, how can add 'reflected' name property on second form too?

thanks.

i presume user may change value in name control, don't need change in second form , need send along data. in scenario, need hidden input in second form, value of name property stored:

<form id="firstform">          @html.editorfor(model => model.name, new { id = "yournameinput" }) //need property on both forms, in second form readonly input value.    @html.validationmessagefor(model => model.name, string.empty})    <button type="submit" id="btnsearchname"></button> </form>  //second form @using (html.beginform()) {    @html.hiddenfor(model => model.name, new { id = "yourhiddeninput" })    //other inputs other properties in userdto viewmodel    <input type="submit" class="btn btn-success btn-lg" value="save" /> } 

when submitting first form, copy value of name property in hidden field of second form:

<script> $("#firstform").submit(function (e) {         e.preventdefault();         if (!$(this).valid()) {             return false;         }          $("#yourhiddeninput").val($("#yournameinput").val());          findname(); //ajax request         return true; // if true, expand(show) second form     }); </script> 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -