MVC3 null Querystring返回到操作方法



似乎一旦我定义了我的Form,就像-->
使用(Html.BeginForm("创建"、"MyController"、FormMethod.Post、new{id="myForm"}))

正在传递的附加参数现在为null。

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

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

使用Request["myparameter"]或简单地从操作方法参数中获取值将返回null。

试试这个

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

你说的很奇怪,因为以下内容对我来说非常好:

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" />
}

最新更新