
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.19 KB | hits: 16 | expires: Never
View not found when a view model is specified
using MyProject.ViewModels;
[ChildActionOnly]
public PartialViewResult ShowMyView(int id)
{
return PartialView(new MyModel() { ModelID = id });
}
namespace MyProject.ViewModels
{
[Bind(Exclude = "ModelID")]
public class MyModel: IValidatableObject
{
public MyModel()
{
Count = 1;
}
[Required]
[HiddenInput(DisplayValue = false)]
public int ModelID { get; set; }
[Required]
[Range(1, 9999)]
public int Count { get; set; }
public IEnumerable<ValidationResult> Validate(
ValidationContext validationContext)
{
if (ModelID <= 0)
yield return new ValidationResult("Model ID missing",
new[] { "ModelID" });
if (Count <= 0)
yield return new ValidationResult("Count cannot be zero",
new[] { "Count" });
}
}
}
@inherits WebViewPage
@inherits WebViewPage<MyProject.ViewModels.MyModel>
@inherits WebViewPage<MyProject.ViewModels.MyModel>
@model MyProject.ViewModels.MyModel
@Html.Action("ShowMyView", "SomeController", new { id = "123" })