在MVC中显示ID为ID的URL

时间:2014-11-07 20:57:32

标签: asp.net-mvc

我是MVC的新手,所以我仍在学习。我正在提交表单,我需要获取其中一个文本框的数据并将其传递给URL。我的Routeconfig是默认的,所以我知道我有正确的路线,现在这是我的控制器:

    AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Verify(string verificationString)
    {

        return View();
    }

我的观点是:

 @using(Html.BeginForm("Verify", "Status", FormMethod.Post)) {
     @Html.AntiForgeryToken()

@Html.TextBoxFor(m => m.verificationCode, new { @name="verificationID", @class = "form-control", @maxlength = "18", @required="required" })
 }

我不知道如何在URL中传递此变量,因此它显示/ Status / Verify / verificationstring(文本框数据)。我怎么能这样做?

编辑:RouteConfig

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

编辑:FullView

  @model LSFVerif.Models.StatusModel
 <div class='form-group' style="text-align:center">

  @using(Html.BeginForm("Verify", "Status", FormMethod.Post)) {
     @Html.AntiForgeryToken()
 @Html.ValidationSummary(true)

  @Html.TextBoxFor(m => m.Email, new { @class = "form-control", @type="email", @placeholder = "Email", @maxlength = "100", @required="required" })


 @Html.TextBoxFor(m => m.VerificationCode, new { @name="VerificationCode", @class = "form-control", @placeholder = "Codigo", @maxlength = "18", @required="required" })


          <button class='btn-lg btn-primary' type='submit'>Verify</button>

}

2 个答案:

答案 0 :(得分:1)

    @using (Html.BeginForm("Verify", "Status", FormMethod.Post))
    {
        @Html.AntiForgeryToken()

        @Html.TextBoxFor(m => m.verificationCode, new { @class = "form-control", @maxlength = "18", @required = "required" })
     <input type="submit" value="Submit" />
    }
and 

     [HttpPost]
     public ActionResult Verify(string verificationCode)
    {

          return RedirectToActionPermanent("Vierified", "Status", new
            {
                id = verificationCode
            });
    }

        [HttpGet]
        public ActionResult Vierified(string verificationCode)
        {
            return View("Vierified");
        }

答案 1 :(得分:0)

只需将参数更新为:

AcceptVerbs(HttpVerbs.Post)]
public ActionResult Verify(ThisShouldBeTheNameOfYourModel model)
{

    return View();
}