簡體   English   中英

將數據從Html.EditorFor傳遞到控制器

[英]Pass data from Html.EditorFor to controller

如何將Html.EditorFor中的數據傳遞給myController中的myAction?

這是我的編輯器:

<div class="editor-label">
            @Html.LabelFor(model => model.Quote_Currency)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Quote_Currency, new { })
            @Html.ValidationMessageFor(model => model.Quote_Currency)
        </div>

這是我的控制器動作:

public ActionResult SaveQuote(FxQuote quote, string Quote_Currency)
        {


                objQuote.Quote_Currency = Quote_Currency;

                dcfx.FxQuotes.InsertOnSubmit(quote);
                dcfx.SubmitChanges();


            return View();

在這里,我正在嘗試使用一個與我的編輯器同名的參數,但這不起作用。 請幫忙。

您可以將FormCollection collection作為附加參數添加到控制器方法。 該集合將保存從控制器中的視圖傳遞的所有數據。 您可以使用調試器來探查哪些數據正正確發送到控制器。

您為什么不只是更改操作以接受模型?

像這樣:

 public ActionResult SaveQuote(ModelType model) 
 { 


            objQuote.Quote_Currency = model.Quote_Currency; 

            dcfx.FxQuotes.InsertOnSubmit(model.Quote); 
            dcfx.SubmitChanges(); 


        return View();
  }

或者,您可以更改它以接受另一個答案中提到的表單集合:

 public ActionResult SaveQuote(FormCollection collection) 

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM