Server-side Validation using MVC 3
I'm building an ASP.NET MVC3 app. I have 2 views;
- List item contains a grid
- details view consists of a drop down list (combobox)
I have a requirement to alert the user at the details view when they try to select item was previously selected in the list view. In other words, the grid should contain unique items
What is the best way to implement a server-side business logic validation?
Model:
public class AllocatedResource
{
public virtual Project Project { get; set; }
开发者_开发问答 public virtual DateTime StartDate { get; set; }
public virtual DateTime EndDate { get; set; }
}
List View:
@(Html.Telerik().Grid(Model.AllocatedResources)
.Name("gridAllocatedProject")
.DataKeys(keys =>{keys.Add(p => p.Id);})
.Columns(columns =>
{
columns.Bound(p => p.Id).Visible(false);
columns.Bound(p => p.Project.Name);
columns.Bound(p => p.Project.ProjectManager).Title("Project Manager");
columns.Bound(p => p.StartDate).Width(80).Format("{0:d}");
columns.Bound(p => p.EndDate).Width(80).Format("{0:d}");
})
Details View:
@Html.Label("Project: ")
@(Html.Telerik().ComboBox().Name("Project")
.BindTo(new SelectList(Model.AllProjects, "Id", "Name"))
.Value(Model.AllocatedResource.Project.Id.ToString()))
@Html.Label("Start Date: ")
@(Html.Telerik().DatePicker().Name("StartDate")
.Value(Model.AllocatedResource.StartDate))
@Html.Label("End Date: ")
@(Html.Telerik().DatePicker().Name("EndDate")
.Value(Model.AllocatedResource.EndDate))
精彩评论