部分视图操作导致404错误

时间:2015-03-19 16:42:34

标签: javascript c# ajax asp.net-mvc

我在视图中有这段代码:

@if (User.Identity.IsAuthenticated)
{
    @Html.Partial("_PostCommentPartial", new PostCommentViewModel(Model.Id))
}

在我的部分观点中:

@using (Ajax.BeginForm("PostComment", "SecondComments",
    new AjaxOptions
    {
        HttpMethod = "POST",
        InsertionMode = InsertionMode.InsertBefore,
        UpdateTargetId = "comments"
    }))
{
@Html.AntiForgeryToken()

@Html.HiddenFor(m => m.TicketId)
@Html.EditorFor(m => m.Content)

<div class="col-md-5">
    <input type="submit" class="btn btn-default pull-right" />
</div>
}

我的控制器:

public class SecondCommentsController : BaseController
{
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult PostComment(PostCommentViewModel comment)
    {
        // some codes here
    }
}

当我点击提交按钮时,我收到500错误。请指教。

编辑我的控制器继承的基本控制器类:

[HandleError]
public class BaseController : Controller
{
    protected ITicketSystemData Data { get; private set; }

    protected User UserProfile { get; private set; }

    public BaseController(ITicketSystemData data)
    {
        this.Data = data;
    }

    protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
    {
        this.UserProfile = this.Data.Users.All().Where(u => u.UserName == requestContext.HttpContext.User.Identity.Name).FirstOrDefault();

        return base.BeginExecute(requestContext, callback, state);
    }
}

0 个答案:

没有答案