Code given below sends an ajax request to the controller.
if (btid === '01') {
var allData = {
"sessionName": $('#sessionname').val(),
"foundStudent": $('#studentId').val(),
"code":btid
}
var mySession = JSON.stringify(allData);
$.ajax({
type: "POST",
url: '@Url.Action("RenderView", "ManualFeesCollection")',
contentType: "application/json; charset=utf-8",
data: mySession,
success: function (data) {
$('#maindiv').html('')
$('#maindiv').html(data)
$.each(data.myMonths, function (index, item) {
//Here I want to access myMonths as Json
})
},
})
Below in the Controller Action.
public ActionResult RenderView(int code,long foundStudent,int sessionName)
{
var months = //get some months
var myMonths= (from w in months
select new
{
w.Month
});// Want access this data in ajax success function
return PartialView("MonthwiseFees",myMonths);
}
But the problem is I am getting the view in the #maindiv,but not not getting
myMonths
as json, in the success function of ajax. I need to do something in view with those myMonths.Currently I am sending two ajax request(in the success of another) to accomplish.But I wish I could do it with a single ajax request.Thanks for spending time on my Issue.
Update1: code of partial view
{ <tr> <td> @x </td> <td> @months[no] </td> <td> @Html.CheckBox(" " + @x, new { @class="check",id="check"}) @Html.Label(" ", new { @class="lbl"}) </td> </tr> x = x + 1;
}
<input type="button" class="mybutton btn btn-small btn-primary" value="Show >"/> </div> <div class="span7" id="classwiseheads"> </div> </div>