将表单值从一个控制器视图传递到 asp MVC 中不同控制器视图上的另一个表单

Passing form values from one controller view to another form on a different controllers view in asp MVC

好的,我是 MVC 的新手,我正在尝试创建一个网页,我可以在其中转移到带有邮政编码和按钮的小表单框,然后转到将在报价页面上填写邮政编码部分的报价页面。

我的问题是我有两个控制器,一个 homeController,它有一个带小表单框的索引视图。我需要将邮政编码传递给 QuoteController,它有自己的视图,其中填充了新的邮政编码。

家庭控制器输入,indexview

 @using (Html.BeginForm("Quote", "Quote"))    
  <p>Move From Zip:</p>  
 <input type="text" name="Zip"/><br /> 
 <input type="submit" value="Next" name="next">

用于接收 zip 的报价单,在报价控制器上,在报价视图上

@Html.Label("Move From Zip ")<br />
@Html.TextBoxFor(m => m.MoveFromZip, "", new { maxlength = 5, @class =    "short-textbox" })

最简单的方法是什么

在 HomeController 的索引视图中,您可以将表单操作保留为 "Quote/Quote"

@using (Html.BeginForm("Quote", "Quote"))
{
  <input type="text" name="Zip" />
  <input type="submit" />
}

QuoteController

中为您的报价操作方法视图创建视图模型
public class QuoteVm
{
  public string Zip { set;get;
}

并在您的 QuoteController 的报价操作方法中

[HttpPost]
public ActionResult Quote(QuoteVm model)
{
  return View(model);
}

您的报价视图将是

@model QuoteVm
<p>Data passed(POSTED) from Index view</p>
@using(Html.BeginForm("QuoteSave","Quote"))
{  
  @Html.TextBoxFor(s=>s.Zip)
  <input type="submit" />
}

现在,对于在此视图中提交的表单,您需要另一个 HttpPost 操作方法

[HttpPost]
public ActionResult QuoteSave(QuoteVm model)
{
   // to do : Do something and return something
}