I'm currently working on a ASP.NET MVC 4 project as a trainee and I'm trying to implement an admin panel. The goal is to show all the users on a grid (MVC.GRID) and edit them on the same page. I've managed to show all the users on the grid and once a user is selected it shows the info below the grid and puts it in a form (via ajax/jquery).
The problem is: the form validation is being displayed on a new page and not on the page where the grid is at. And I've no idea why..
Below is my code.
This is where the form is placed:
<div id="order-content">
<p class="muted">
Select a user to see his or her information
</p>
</div>
The form itself (partial view "_UserInfo):
@using (Ajax.BeginForm("EditUser", "Admin", FormMethod.Post,
new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
UpdateTargetId = "order-content"
}))
{
@Html.Bootstrap().ValidationSummary()
@Html.Bootstrap().ControlGroup().TextBoxFor(x => x.Id)
@Html.Bootstrap().ControlGroup().TextBoxFor(x => x.Name)
@Html.Bootstrap().ControlGroup().TextBoxFor(x => x.Password)
@Html.Bootstrap().SubmitButton().Text("Opslaan").Style(ButtonStyle.Primary)
}
JQuery to show the user info once a row is selected:
$(function () {
pageGrids.usersGrid.onRowSelect(function (e) {
$.post("/Admin/GetUser?id=" + e.row.Id, function (data) {
if (data.Status <= 0) {
alert(data.Message);
return;
}
$("#order-content").html(data.Content);
});
});
});
My AdminController:
[HttpPost]
public JsonResult GetUser(int id)
{
var user = _UserService.Get(id);
var input = _EditInputMapper.MapToInput(user);
if (user == null)
return Json(new { Status = 0, Message = "Not found" });
return Json(new { Content = RenderPartialViewToString("_UserInfo", input) });
}
[HttpPost]
public ActionResult EditUser(AdminUserEditInput input)
{
if (ModelState.IsValid)
{
// todo: update the user
return View();
}
// This is where it probably goes wrong..
return PartialView("_UserInfo",input);
}
Can anyone see what is wrong with my code?
Thank you.