javascript - How to change attribute of Html.Beginform() on form Submitting -


i have far:

 <% foreach (object object in collection)  {      u<% using (html.beginform("actionname", "controller", new { fu = "bar" }, formmethod.post, new { id = "myid"}))       {%>         <input type="submit" value="submit" />       <%}  } %>   $('#myid').submit(function() {      var url = url.action("actionname", "controllername");      var fu = "newvalueoffu"; // new value fu      $('#myid').prop('action', url + "?fu=" + fu);  }); 

i want change value of fu value jquery

simplified answer.

you using incorrect overload. see overloads list on msdn idea of use.

your current overloads expects routing information 3rd parameter. values provide matched against routes defined site. if parameters not match it, added parameters.

what trying achieve assign id or attribute form. done using overload allows html attributes defined (see overload on msdn. eg,

@using(html.beginform("action", "controller", formmethod.post, new {id = "myid"})) 

note: order of parameters different.

simply @ html generated , idea of happening.

// update

use this

@using(html.beginform("action", "controller", new {fu="bar"}, formmethod.post, new {id = "myid", onsubmit="return sayhello()"})) 

this generate html similar to

 <form action="/controller/action?fu=hello" method="post" id="myid" onsumbit="return sayhello()"> 

and combined script

<script>     function sayhello()     {         alert("hello");         return true;     } </script> 

will give alert, sending fu controller.

// update how can update action attribute of form.

<script>   $('#myid').submit(function() {       var url = @url.action("action","controller");       var fu = "newvalueoffu"; // new value fu       $('#myid').prop('action', url + "?fu=" + fu;       return true;   }); </script> 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -