繁体   English   中英

MVC3空查询字符串返回到操作方法

[英]MVC3 null Querystring Returned To Action Method

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

现在,传递的其他参数为空。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM