//HomeController.cs
User model = new User();
public ActionResult Index()
{
model.Name = "Michael";
model.Address = "Chennai";
model.ContactNo = "8976564321";
return View(model);
}
[HttpPost]
public ActionResult Index(string Name, string Address,string ContactNo)
{
model.Name = Name;
model.Address = Address;
model.ContactNo = ContactNo;
return View(model);
}
//Index.cshtml
@{Html.EJ().Dialog("lognForm").Title("Login Form").ShowOnInit(false).IsResponsive(true).Containment(".control").ContentTemplate(@<div>
@using (Html.BeginForm("Index","Home")) {
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<p>
@Html.EJ().Button("Save").Text("Save").Type(ButtonType.Submit)
@Html.EJ().Button("Cancel").Text("Cancel").Type(ButtonType.Submit)
</p>
}
</div>).EnableResize(false).Width(500).ClientSideEvents(evt => evt.Close("onDialogClose")).IsResponsive(true).Render();} |
//Index.cshtml
function onclick1(args) {
//getting the textbox values from the dialog
var name = $('#Name').val();
var address = $('#Address').val();
var contactno = $('#ContactNo').val();
var jsonObject = {
"Name": name,
"Address": address,
"ContactNo":contactno
};
$.ajax({
url: '@Url.Action("Index")',
type: 'POST',
data: JSON.stringify(jsonObject),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
document.getElementById("name").innerHTML = result.Name;
document.getElementById("address").innerHTML = result.Address;
document.getElementById("contactno").innerHTML = result.ContactNo;
}
});
}
//HomeController.cs
[HttpPost]
public JsonResult Index(User model)
{
return Json(model);
} |