This is in accordance to my question:
How to pass array created from jQuery to controller method?
Here is my controller returning a partial view:
public ActionResult PartialViewChild(int id)
{
//stmts /*model is assigned here */
return PartialView("ChildPartialView", model);
}
My problem now is that, the view returned from my controller action is not rendered by $.ajax()
call. I had put a debugger in the success function, it never hit there. So, by chance, I added a error function also in ajax call like,
var id=currentSelected.Id;
$.ajax({
url: "@(Url.Action("PartialViewChild", "ControllerChild")",
type: "POST",
data: JSON.stringify({id : id}),
cache: false,
success: function (result) {
$("#id1").html(result);
},
error: function (data, errorThrown) {
alert('request failed :' + errorThrown);
}});
I also found out that, the div with id "id1" must be empty for the partial view to be rendered correctly. But, that div at the start renders a EmptyView like,
<div id="id1">
@{Html.RenderPartial("ChildPartialView", new ChildPartialModel());}
</div>
and based on the ajax call, I wanted to fill in that div with the returned result (by now all the attributes will have value).. But, unfortunately, here I only had the alert of error:() from ajax call telling me that there was a "Parse error".
Can someone tell me how can I correct it?
EDIT:
This is my Partial View:
@model Models.ChildColumnsModel
<div>
<span>@Html.LabelFor(c => c.Phone_Number):</span>
<span>@Html.TextBoxFor(c=> c.Phone_Number)</span>
</div>
// like this it has all its attributes...
and in my controller:
public PartialViewResult PartialViewChild(int id)
{
var model=child.GetReletedInfo(id); /*proper results are returned here which is of ChildColumnsModel type */
return PartialView("ChildPartialView", model);
}
SORRY ALL... I resolved the issue. I had an extra property for ajax telling its dataType: "Json"... when I removed it, All was FINE.. How silly of myself..?!! Thank you all for your VALUABLE answers and TIME friends..