ASP.NET MVC 3 Validation
i have a tables Service with "Price" and "Discount" fields and ServiceLanguage with "开发者_运维百科Name" and "Description" fields. in the View i using ServiceLanguage as a model. so i create a partial class for validation.
public string Name { get; set; }
public string Description { get; set; }
this works greate. but also i need to validate Price and Discount
public expm_Service expm_Service.MaxDiscount{ get; set; }
public expm_Service expm_Service.Price { get; set; }
and this doesn't work greate. the problem is:
Error 1 The modifier 'public' is not valid for this item
how can i validate Price and Discount? any help?
Not sure if this is what your after, as its a bit hard to understand your question, but check out this link, it describes attribute based validation on your model. Then you can apply that to your Price and Discount properties.
It looks like your trying to declare two properties into your model from "expm_Service". The declarations don't make much sense.
You need to add MaxDiscount and Price to your model in the same way as you've done for Name and Description. Then you can pass the values to and from the model via your service.
E.g.
public string MaxDiscount { get; set; }
public string Price { get; set; }
Plus any DataAnnotations to set validation rules on those.
精彩评论