This is the first time I am working with ASP.NET MVC and I am stuck.
In my code I am doing an Ajax call by using JQuery/json, passing an array of selected options on button click to the controller side and performing some operations there.
Then I return a Partial View
which is containing a table so I can see the contents of the Partial View (i.e., Grid) on the page.
Now I want go through the grid but when I try to inspect it I realize that there is no HTML code created in the browser's View Source
.
Am I missing any basic thing over here? Can anyone help on this?
Controller - Main action method for View :
public ActionResult AssignCalculationToSC()
{
//Some Oprations performed
return View();
}
Action method called from Ajax to return Partial View :
public ActionResult AddSelectedList(string selectedList, string calculationPurpose)
{
List<AssignCalculationsSourceDataModel> lstAssignCalculationsSourceDataModel = new List<AssignCalculationsSourceDataModel>();
AssignCalculationsSourceDataModel assignCalculationsSourceDataModel = new AssignCalculationsSourceDataModel();
return PartialView("AssignCalculationToSC", lstAssignCalculationsSourceDataModel);
}
JQuery code for Ajax call :
$(function () {
$('#btnAdd').click(function () {
var selectedList = [];
$("#ddlSupplementalCalculationList option:selected").each(function (i, selected) {
var $this = $(this);
selectedList.push({ Id: $this.val(), Value: $this.text() });
});
getCalculationListGrid(selectedList, calculationPurpose);
});
function getCalculationListGrid(selectedList, calculationPurpose) {
$.ajax(
{
url: "AddSelectedList/SupplementalPricing",
type: "POST",
dataType: "html",
traditional: true,
data: { selectedList: JSON.stringify(selectedList), calculationPurpose: calculationPurpose },
success: function (response)
{
$("#dvGrid").html(response);
}
});
}
});
Main View :
@{
ViewBag.Title = "Assign Price Values";
}
@model IList<Bnym.Equinox.Accounting.Web.Portal.Models.Pricing.AssignCalculationsSourceDataModel>
@{Html.RenderPartial("PartialAssignCalculationGrid", Model);}
Partial View :
@model IList<Bnym.Equinox.Accounting.Web.Portal.Models.Pricing.AssignCalculationsSourceDataModel>
@if (Model != null)
{
<div id="dvGrid">
<table id="grid" style="table-layout: fixed;">
</table>
</div>
}
dvGrid
. However, this div isn't into the main view, it's from the partial view itself. You should have a placeholder on your main view. – Andre Calil