2

如何将数据从 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();

在这里,我试图有一个与我的编辑器同名的参数,但这不起作用。请帮忙。

4

2 回答 2

1

您可以将 aFormCollection collection作为额外参数添加到控制器方法中。该集合将保存从控制器中的视图传递的所有数据。您可以使用调试器来探索哪些数据正在准确地发送到控制器。

于 2012-07-10T18:31:39.247 回答
0

你为什么不改变动作来接受你的模型?

像这样的东西:

 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) 

希望这可以帮助

于 2012-07-10T18:37:20.503 回答