2016-02-05 72 views
0

好吧,我是新來的MVC,並試圖使我成爲一個網頁,我可以轉移到一個小型表格與郵政編碼和按鈕,引用將在報價頁面上填寫郵政編碼部分的頁面。將窗體值從一個控制器視圖傳遞到另一個窗體在不同的控制器視圖在asp 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"> 

報價表接收拉鍊,報價控制器上,在報價查看

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

什麼這樣做

的最簡單方法
+0

這裏是家庭控制器輸入 – theone

+0

在這裏?在哪裏? ... – Shyju

+0

@using(Html.BeginForm(「Quote」,「Quote」)) {

Move From Zip:


} – theone

回答

1

在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 
} 
+0

感謝它的工作,但我不知道爲什麼?我只使用了您在當前QuoteModel類中提供的代碼的第二塊代碼,其中我的驗證是,然後我添加的是開始表單方法中的項目,並且它的工作原理其他內容對傳輸沒有影響。 – theone

+0

但還有一個問題,當數據傳輸到引用頁面時,它會觸發我所有的驗證,我該如何防止它。 – theone

相關問題