I’m new to ASP.NET MVC 3 and I’m trying to create a edit view for a User-object that has a couple of relations. I have the basic edit-view for the user, split with tabs for each relation that needs to be handled.
Tab 1 = Edit User
Tab 2 = Create new Group Access (with a listing of current group access)
and so on…
I created a ViewModel for the edit-view:
public class UserViewModel
{
public User User { get; set; }
public GroupAccess GroupAccess { get; set; }
public IEnumerable<GroupAccess> GroupAccessList { get; set; }
}
The edit-view:
@model Project.ViewModels.UserViewModel
<div class="row">
<div class="span9">
<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">User Information</a></li>
<li><a href="#tab3" data-toggle="tab">Group Access</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
@{ Html.RenderPartial("User/_CreateEditUser", Model.User); }
</div>
<div class="tab-pane" id="tab3">
@{ Html.RenderPartial("User/_CreateGroupAccess", Model.GroupAccess); }
@{ Html.RenderPartial("User/_ViewGroupAccessByUser", Model.GroupAccessList); }
</div>
</div>
</div>
</div>
@{ Html.RenderPartial("_SidebarPartial"); }
</div>
Each of the partialviews are strongly-typed against their respective object…
The partialviews posts to the same controller, UserController, to separate actions. Everything works fine when saving “correct” data but when some kind server-side error occurs I need to return to the edit-view somehow. If I receive a server-side error in the “CreateGroupAccess” action in the UserController…how do I get back to the edit-view with the UserId-parameter that is required?
I’m stuck and I’m guessing that I’m going in the wrong direction with the current solution.
Does anybody got any idea on how to best solve this scenario?
Make yourself an BaseController:
BaseController
SomeOtherController