开发者

asp.net ChangeAction - simple tutorial question

开发者 https://www.devze.com 2023-01-20 07:41 出处:网络
partial void OnValidate(ChangeAction action) { if (!IsValid) throw new ApplicationException(\"Rule violations prevent saving\");
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号