asp.net mvc 3 - Unable to pass routing values from jquery to mvc action method -
javascript
<script type="text/javascript"> $(function () { $("[id*=btnadd]").click(function () { //here passing routing value i.e student var url = '@url.action("getpv", "home", new { students=model.students })'; $('#grid1').load(url); }); });
html
<div id="grid1"></div> <input type="button" id="btn" value="submit"/>
mvc action
//here iam getting students parameter null
public actionresult getpv(list<student> students) { students.add(new student()); studentmodel objstudentmodel = new studentmodel(); objstudentmodel.studentlist = students; return partialview("_demopv", objstudentmodel); }
model
public class studentmodel { public list<student> studentlist { get; set; } } public class student { public int id { get; set; } public string name { get; set; } public string mobile { get; set; } public string email { get; set; } public string nationality { get; set; } public list<httppostedfile> files { get; set; } }
i want load partial view through jquery on button click event.
in scenario, want pass student list parameter action method.
here not able pass routing values jquery url action mvc action method.
please assist me resolve issue. thanks.
try this
<script type="text/javascript"> $(function () { var _post_student_list = new array(); var templiste = { id: '@model.student.id', name: '@model.student.name', mobile: '@model.student.mobile', email: '@model.student.email', nationality: '@model.student.nationality' } _post_student_list.push(templiste); var finalmodel = { student: { id: '@model.student.id', name: '@model.student.name', mobile: '@model.student.mobile', email: '@model.student.email', nationality: '@model.student.nationality' }, studentlist: _post_student_list, } $("#btnadd").click(function () { $.ajax({ url: '@url.action("getpv", "home")', data: json.stringify({ st: finalmodel }), datatype: 'json', type: 'post', contenttype: "application/json; charset=utf-8", success: function (data) { $("#grid").load(url); } }); }); }); </script> <div id="grid"></div> <input type="button" id="btnadd" value="submit"/> public actionresult getpv(studentmodel st) { students.add(st.student); studentmodel objstudentmodel = new studentmodel(); objstudentmodel.studentlist = st.studentlist; return view("~/views/home/_demopv.cshtml", objstudentmodel); } public class studentmodel { public studentmodel() { this.student = new student(); } public student student { get; set; } public list<student> studentlist { get; set; } } public class student { public int id { get; set; } public string name { get; set; } public string mobile { get; set; } public string email { get; set; } public string nationality { get; set; } public list<httppostedfile> files { get; set; } }
Comments
Post a Comment