从局部视图提交后重定向

时间:2013-10-24 18:15:40

标签: c# asp.net-mvc redirect partial-views

这是我的部分观点

   @model OpenRoad.Web.Areas.Marketing.Models.AgreementModel


     <script type="text/javascript">
         $(document).ready(function () {

             $('#agreementcheckbox').change(function () {
                 if (this.checked) {
                     $('#btn_next').show();
                 }
                 else {
                     $('#btn_next').hide();
                 }
             });
         });

     </script>


@using Telerik.Web.Mvc.UI;
@using (Html.BeginForm("Agreement", "LeadPipes",FormMethod.Post)) 
{
    @Html.HiddenFor(m=>m.SiteId);
     @Html.HiddenFor(m=>m.Email);
    @Html.HiddenFor(m => m.CountyID);
    @Html.HiddenFor(m => m.HasNationWideLeadpipes);
    @Html.HiddenFor(m => m.Time);
     @Html.HiddenFor(m=>m.LeadType);

<h2>Agreement</h2>
<p>I agree to make sure that all of my communication will be in compliance with both federal and state regulations governing securities.  I acknowledge that it is against federal and state Securities and Exchange Commission laws to solicit loans in an improper manner.  Prior to using Realeflow to download various potential private investor leads, I agree that I am fully liable and responsible for knowing the laws of my state as well as the federal SEC laws.  I will not hold Realeflow, LLC responsible in any way for my violation of those laws.
</p>
    <br />
<span><input type="checkbox" id="agreementcheckbox" /> I have read and acknowledge the compliance.</span>
<div id="btn_next" hidden="hidden">
<span class="btn_add"><input type="submit" value="Next" id="btnSubmit"/></span>

</div>
}

这是控制器,但它不会让我重定向到我在代码中列出的页面。有人可以向我解释如何正确地将其重定向到列出的页面。

[HttpPost]
        public ActionResult Agreement(Models.AgreementModel model)
        {
            if (model.LeadType != null)
            {                
                return Redirect("~/List?hasNationWideLeadPipes=" + model.HasNationWideLeadpipes + "&leadtype=" + model.LeadType);
            }
            else return Redirect("~/List");

        }

感谢

1 个答案:

答案 0 :(得分:1)

首先,不要对URL进行硬编码。代替:

return RedirectToAction("List", new {
    hasNationWideLeadPipes = model.HasNationWireLeadpipes,
    leadtype = model.LeadType
});

让路由框架按照自己的意图行事。