asp.net ChangeAction - simple tutorial question
partial void OnValidate(ChangeAction action) {
if (!IsValid)
throw new ApplicationException("Rule violations prevent saving");
}
i am following this tutorial:
http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf
and am not able to compile the above code. it is in my NerdDinner.Models.Dinner
am i placing it in the wrong location?
here's the class:
public partial class Dinner {
public bool IsValid {
get { return (GetRuleViolations().Count() == 0); }
}
public IEnumerable<RuleViolation> GetRuleViolations() {
yield break;
}
partial void OnValidate(ChangeAction action) {
if (!IsValid)
throw new ApplicationException("Rule violations prevent saving");
}
}
here's the error im getting
Error 1 The type or namespace name 'ChangeAction' could not be found (are you missin开发者_如何学编程g a using directive or an assembly reference?)
please excuse the beginner's question and please let me know if you need any other details. im almost certain that im missing something fundamental here. can anyone please help with this? just run me through the necessary steps?
You're referencing ChangeAction
by its unqualified name, so you have to make its namespace visible from your module:
using System.Data.Linq;
If the above gives an error, you probably also should add the System.Data.Linq
assembly to your project's references.
精彩评论