c# - Pass model values to controller in using jQuery Post () -


the application in .net framework 3.5 , mvc framework 2.0 .net framework 3.5. have view in $.post passes parameters. need $.post , passes model values controller.

in view below , how pass model in $.post function, controller gets value of textbox. need button , not submit button.

the view is:

<div>         <label ="name"> name</label> &nbsp; <%=@html.textboxfor(m => m.name) %>         <select id ="prod" style ="width:150px">             <option value ="gl">gl</option>             <option value = "property"> property</option>             <option value = "package">package</option>             <option value = "island">island</option>         </select>          <input type="button" id="btnpost" value = "getvalue" /> </div> 

   <script src="/scripts/jquery-1.4.1.min.js" type ="text/javascript"></script>     <script type ="text/javascript" >          $(function() {          $("#btnpost").click(function() {         alert("here" + $("#prod").val());         $.post("/transfer/displaytext", { "str1": $("#prod").val()},            function(data) {            alert("success");        });     });  }); 

th controller is:

[httppost]     public actionresult displaytext(string         str1,testpost_ajaxmvc.viewmodels.transferviewmodel model)      {         string str2 = str1;         return view("transfer");      } 

the model :

 public class transferviewmodel   {       public string name { get; set; }   } 

i think ok in code replace

$.post 

to $.get because returning view controller use url.action below because may not work when publish project

$.get('<%=url.action("displaytext","transfer")%>', { str1: $("#prod").val()},            function(data) {            alert("success");        }); 

you should remove double quote str1.let me know if not work.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -