到MVC3控制器方法我很新,并具有环绕我周围的事物头的问题。现在我有一个局部视图,我简化如下:PartialView表单验证,然后调用MVC3
@model blah.blah.blah.blah.ForumPost
@using (Html.BeginForm()) {
<fieldset>
<legend>ForumPost</legend>
<div class="editor-label">
@Html.LabelFor(model => model.ForumID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ForumID)
@Html.ValidationMessageFor(model => model.ForumID)
</div>
<p>
<input type="submit" value="Create" />
@Html.ValidationSummary(true)
</p>
</fieldset>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
}
我不是做什么的表单验证。我一直在尝试使用jquery验证,但我似乎找不到适合我所做的并且迷失方向的好例子。我以此为例here,但这还不够。
我做了后,我想打电话给一些代码的方法,我真的不知道一个干净的方式来做到这一点。我目前的工作方式是使用ajax调用,这真的很难看。还有一位同事建议我将该方法通过一个实际的论坛帖子,但我不知道如何。我想要调用的方法的代码如下:
public void PostToForum(ForumPost post)
{
UserService cu = new UserService();
int PostUserID = cu.GetUserIDByUsername(base.User.Identity.Name);
if (this.ModelState.IsValid)
{
ForumPost nfp = service.CreateForumPost(post);
}
}
任何人都有一些提示?谢谢。
,如果有必要,我可以提供更多的代码。
没有在MVC3 –
“后面的代码” @TetsujinnoOni遗憾,就像我说我很新的MVC3,我不知道该怎么称呼它。 – yaegerbomb
没问题,不需要道歉。这是一种非常不同的方法来控制页面上的怪异东西(称为生命周期)。 –