What i want to achieve
- Initiate jQuery ajax get request if radio button is selected
- Retrieve Model object as json response with values
- Using that model object display data on razor view
I am stuck in third step.How can i use model object to display data on razor view
P.S. I am able to get alert as "Building No : 1" from my ajax code
JS
$('input[name=PerAddress]').on('change', function () {
if ($('input[name=PerAddress]:checked', '.form-group').val() == 'true') {
$.ajax({
url: "CAD",
type: 'GET',
dataType: 'json',
success: function (data) {
alert(data.PresentAddress1);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
});
Controller Action Method :
[HttpGet]
[ActionName("CAD")]
public JsonResult CustomerAddress()
{
var model = new AccountOpeningComplete
{
PresentAddress1 = "Building No : 1", // To be later retrieve from database
PresentAddress2 = "Mumbai", // To be later retrieve from database
PresentPostalCode = "497989", // To be later retrieve from database
CityList = new SelectList(DataAccess.DAL.DropDownValues("City"), "Value", "Text"),
ProvinceList = new SelectList(DataAccess.DAL.DropDownValues("Province"), "Value", "Text"),
CountryList = new SelectList(DataAccess.DAL.DropDownValues("Country"), "Value", "Text")
};
return Json(model, JsonRequestBehavior.AllowGet);
}
Razor View
@Html.LabelFor(m => m.PresentAddress1, new { @class = "col-xs-6 col-md-3 control-label" })
<div class="col-xs-6 col-md-9">
@Html.TextBoxFor(m => m.PresentAddress1, new { @class = "form-control" })
</div>