Asp.net mvc mvc在post期间维护url参数

Asp.net mvc mvc在post期间维护url参数,asp.net-mvc,Asp.net Mvc,我目前在以下url上有一个表单设置: http://localhost/mySite/inventory/create/26/1 这是一个actionMethod [HttpGet] public ActionResult create(int exId, int secId) [HttpPost] public ActionResult create(MyModel model, int exId, int secId, FormCollection fo

我目前在以下url上有一个表单设置:

http://localhost/mySite/inventory/create/26/1
这是一个actionMethod

    [HttpGet]
    public ActionResult create(int exId, int secId)


    [HttpPost]
    public ActionResult create(MyModel model, int exId, int secId, FormCollection form)
表单提交和按钮如下所示:

@using (Html.BeginForm("create", "inventory", new { @exId= Model.ExId, @secId= Model.SecId}, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))


无论如何,有没有办法保持get的状态,/create/26/1?

这很可能是一个路由问题。MVC短路路由。换言之,一旦它找到了可行的方法,它就会使用它,即使可能有更好的方法。在这里的场景中,它发现
/inventory/create
是一个有效的路由,并且由于查询字符串参数是任意的,它只是将其余的路由值粘贴在那里。很难说没有看到您的路由配置,但是如果您为
/inventory/create/{exId}/{secId}
创建的路由位于刚刚捕获的任何路由之后,您应该在该路径之前移动它。如果使用属性路由,则没有固有的顺序或路由,因此必须使用路由名称来区分实际要使用的路由

尽管如此,这里最简单的方法就是不生成URL。您正在进行回发,因此可以使用空操作。我认为您之所以会遇到这个问题,主要是因为您试图将
htmlAttributes
传递给
Html.BeginForm
,这需要您指定一些不必要的额外内容。在这些情况下,我建议只使用静态
标记。你不必使用
Html.BeginForm
当你发现自己在做这样的扭曲动作时,最好不要这样做

<form class="form-horizontal" role="form" action="" method="post">
    ...
</form>

...

Genreated markup的form方法设置为POST?@Shyju是的,它显示为
http://localhost/mySite/inventory/create?exId=26&secId=1
<form class="form-horizontal" role="form" action="" method="post">
    ...
</form>