C# ASP.NET MVC Html.Action Render Post而不是GET

C# ASP.NET MVC Html.Action Render Post而不是GET,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我有博客,有时用户会发现我无法重现的错误 Simple PostItem.cshtml: “创建”、“注释”-呈现CreateComment表单 @Html.Action("Create", "Comment", new { @returnUrl = Request.Url, @postID = Model.ID }) <div name="#comments"> @Html.Action("CommentsForPost", "Comment", new { postID

我有博客,有时用户会发现我无法重现的错误

Simple PostItem.cshtml:

“创建”、“注释”-呈现CreateComment表单

@Html.Action("Create", "Comment", new { @returnUrl = Request.Url, @postID = Model.ID })
<div name="#comments">
    @Html.Action("CommentsForPost", "Comment", new { postID = Model.ID })
</div>
@Html.Action(“创建”,“评论”,新建{@returnUrl=Request.Url,@postID=Model.ID})
@Action(“CommentsForPost”,“Comment”,new{postID=Model.ID})
CreateComment.cshtml

<div class="create-comment-container">
@using (Html.BeginForm("Create", "Comment", FormMethod.Post, new { role = "form" }))
{
    @Html.Hidden("returnUrl", Request.QueryString["returnUrl"])
    @Html.HiddenFor(m => m.PostID)
     .........
    <button type="submit" class="btn btn-default pull-right">@L("Post")</button>
}

@使用(Html.BeginForm(“Create”、“Comment”、FormMethod.Post、new{role=“form”}))
{
@Html.Hidden(“returnUrl”,Request.QueryString[“returnUrl”])
@Html.HiddenFor(m=>m.PostID)
.........
@L(“员额”)
}

然后我有了CommentController.cs

        public PartialViewResult Create(int postID, string returnUrl)
        {
            return this.PartialView("Partials/CreateComment", new Comment { PostID = postID });
        }

        [HttpPost]
        [ValidateInput(false)]
        public async Task<ActionResult> Create(Comment comment, string returnUrl)
        {
            var validator = ValidationFactory.CreateValidator<Comment>();

            var results = validator.Validate(comment);

            if (results.IsValid)
            {
                var result = await CommentManager.CreateComment(comment);
                if (result != null && !String.IsNullOrWhiteSpace(returnUrl))
                    return Redirect(returnUrl + "#comments");
            }

            return Redirect("/");
        }

        public PartialViewResult CommentsForPost(int postID)
        {
            return PartialView("CommentsForPost", CommentManager.GetComments(postID, PaginationHelper.GetCurrentPageForName(ControllerContext.RequestContext, "commentPage"), BlogSettings.CommentPageSize));
        }
public PartialViewResult创建(int postID,string returnUrl)
{
返回this.PartialView(“Partials/CreateComment”,新注释{PostID=PostID});
}
[HttpPost]
[验证输入(错误)]
公共异步任务创建(注释、字符串返回URL)
{
var validator=ValidationFactory.CreateValidator();
var结果=validator.Validate(注释);
if(results.IsValid)
{
var result=await CommentManager.CreateComment(comment);
if(result!=null&&!String.IsNullOrWhiteSpace(returnUrl))
返回重定向(返回URL+“#注释”);
}
返回重定向(“/”);
}
公共PartialViewResult评论格式(int postID)
{
返回PartialView(“CommentsForPost”,CommentManager.GetComments(postID,PaginationHelper.GetCurrentPageForName(ControllerContext.RequestContext,“commentPage”),BlogSettings.CommentPageSize);
}
正如你所看到的,所有的动作都带有重定向! 但有些用户捕捉到错误,在主页上重定向它而不保存注释,我的日志中有这个跟踪。 怎么可能呢

HTTP_X_ORIGINAL_URL/comment/create

请求\u方法GET

System.ArgumentException
The parameters dictionary contains a null entry for parameter 'postID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.PartialViewResult Create(Int32, System.String)' in 'geenBlog.Web.Controllers.CommentController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

System.ArgumentException: The parameters dictionary contains a null entry for parameter 'postID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.PartialViewResult Create(Int32, System.String)' in 'geenBlog.Web.Controllers.CommentController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
   at System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
System.ArgumentException
参数字典包含“geenBlog.Web.Controllers.CommentController”中方法“System.Web.Mvc.PartialViewResult Create(Int32,System.String)”的非null类型“System.Int32”的参数“postID”的null条目。可选参数必须是引用类型、可为null的类型或声明为可选参数。参数名称:参数
System.ArgumentException:参数字典包含“geenBlog.Web.Controllers.CommentController”中方法“System.Web.Mvc.PartialViewResult Create(Int32,System.String)”的非空类型“System.Int32”的参数“postID”的空条目。可选参数必须是引用类型、可为null的类型或声明为可选参数。
参数名称:参数
位于System.Web.Mvc.ActionDescriptor.ExtractParameterFromDictionary(ParameterInfo ParameterInfo,IDictionary`2参数,MethodInfo MethodInfo)
位于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)
位于System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.b_u39(IAsyncResult asyncResult,ActionInvokeInnerInvokeState)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
位于System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()中
在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.c__DisplayClass46.b__3f()中
在System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass33.b_u 32(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
位于System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
在System.Web.Mvc.Async.AsyncControllerActionInvoker.c_uuDisplayClass21.c_uuDisplayClass2B.b_u1C()中
在System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass21.b__1e(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
位于System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
在System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCoregreat innerState)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
位于System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
在System.Web.Mvc.Controller.b_uu15上(IAsyncResult asyncResult,Controller)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
在System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)上
位于System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
位于System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResultBase`1.End()
位于System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
在System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequie
 public PartialViewResult Create(int? postID, string returnUrl)
 public PartialViewResult CommentsForPost(int? postID)