2

我有一个标准的 ASP.NET MVC 表单帖子。

例如。

<% using (Html.BeginForm<CommentController>(c => c.Create())) { %>    
..
<% } %>

(and in the controller)

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Comment comment)
{ .. }

现在,我怎样才能让我忽略对象中可能存在的某些值,例如ID或属性?CreatedOnComment

有没有办法可以定义排除/黑名单

4

2 回答 2

3

BindAttribute与 Exclude 标记一起使用

public ActionResult Create( [Bind(Exclude="ID, CreatedOn")]Comment comment )
{
}
于 2009-04-05T02:41:04.120 回答
-2

默认情况下,您在表单 HTML 中的任何输入都将随提交一起传递。

抱歉,我没有想到答案,但我会先研究一些可能的 jQuery 插件和/或一些 AJAX 过滤机制。

于 2009-04-05T02:34:18.237 回答