C# MVC3 null查询字符串返回到操作方法

C# MVC3 null查询字符串返回到操作方法,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,似乎一旦我定义了我的表单--> 使用(Html.BeginForm(“Create”,“MyController”,FormMethod.Post,new{id=“myForm”})) 正在传递的其他参数现在为null MyController/Create/4?pid=61&状态=已启动 pid和status返回null,尽管参数是如上所述传递的。 是什么导致这些querystring参数为null 使用Request[“myparameter”]或仅从action方法参数获取值返回null。

似乎一旦我定义了我的表单-->
使用(Html.BeginForm(“Create”,“MyController”,FormMethod.Post,new{id=“myForm”}))

正在传递的其他参数现在为null

MyController/Create/4?pid=61&状态=已启动

pidstatus返回null,尽管参数是如上所述传递的。 是什么导致这些querystring参数为null


使用Request[“myparameter”]或仅从action方法参数获取值返回null。

您所说的非常奇怪,因为以下内容对我来说非常有用:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(string pid, string foo)
    {
        // the pid and foo parameters are correctly assigned here
        return View();
    }
}
并且认为:

@using (Html.BeginForm("Index", "Home", new { pid = "63" }, FormMethod.Post, new { id = "myForm" }))
{
    @Html.TextBox("foo", "some value")
    <input type="submit" value="OK" />
}
@使用(Html.BeginForm(“Index”,“Home”,new{pid=“63”},FormMethod.Post,new{id=“myForm”}))
{
@TextBox(“foo”,“some value”)
}
试试这个

Html.BeginForm("Create", "MyController", new { pid = Request.QueryString["pid"] },   FormMethod.Post, new { id = "myForm" }))

您能否显示视图和控制器代码,然后我们就可以看到您做错了什么。这是我的操作方法------->公共操作结果创建(WizardViewModel WizardViewModel、int id、int?pid、string SavedJsonRoles、string SavedJsonMetrics、string Status、bool NOVALIDATION){我的隐藏值(例如SavedJsonMetircs)返回时没有问题。@Nate,是的,这也可以作为操作参数使用视图模型。只需确保在请求中传递其他值(pid,status)作为查询字符串参数。请参阅我的示例,了解如何使用Html.BeginForm来实现这一点(我已经硬编码了
pid
值,但是如果当前请求存在,您也可以从当前请求中获取它:
new{pid=Request[“pid”]})
。奇怪的是,如果我将using语句更改为-->using(Html.BeginForm()){}@Nate,是的,这是因为当您使用
Html.BeginForm()时,参数会被传入
helper没有指定任何参数,它只是将当前url用作操作。因此,如果其中有参数,则会自动复制这些url。如果使用其他一些重载,则需要手动指定它们。