c# - ASP.NET MVC InvalidOperationException was unhandled by user code while following book example -
namespace sportsstore.domain.entities { public class product { [hiddeninput(displayvalue = false)] public int productid { get; set; } //[required(errormessage = "please enter product name")] public string name { get; set; } [datatype(datatype.multilinetext)] //[required(errormessage ="please enter description")] public string description { get; set; } //[required] //[range(0.01, double.maxvalue, errormessage = "please enter positive price")] public decimal price { get; set; } //[required(errormessage = "please specify category")] public string category { get; set; } } }
this entity definition, , below action controller.
public viewresult list(string category, int page = 1) { productslistviewmodel model = new productslistviewmodel { products = repository.products.where(p => category == null || p.category == category).orderby(p => p.productid).skip((page - 1) * pagesize).take(pagesize), paginginfo = new paginginfo { currentpage = page, itemsperpage = pagesize, totalitems = category == null ? repository.products.count() : repository.products.where(e => e.category == category).count() }, currentcategory = category }; return view(model); }
i invalidoperationexception complain visual studio when uncomment [required...] in product class. works fine is(commented).
i tried fix , googled can't solve problem myself.
thanks in advance.
Comments
Post a Comment