How do i pass data from a Html.EditorFor to myAction in myController?
如何从Html中传递数据。myAction myController的编辑器?
This is my Editor:
这是我的编辑:
<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>
This is my controller action:
这是我的控制器动作:
public ActionResult SaveQuote(FxQuote quote, string Quote_Currency)
{
objQuote.Quote_Currency = Quote_Currency;
dcfx.FxQuotes.InsertOnSubmit(quote);
dcfx.SubmitChanges();
return View();
Here,i was trying to have a parameter with the same name as my Editor but that did not work. Please help.
在这里,我尝试使用一个与编辑器同名的参数,但这行不通。请帮助。
2 个解决方案
#1
1
You can add a FormCollection collection
as an extra parameter to your controller method. That collection will hold all data passed from the view in the controller. You can use the debugger to explore which data is exactly being sent to the controller.
您可以添加一个FormCollection集合作为控制器方法的额外参数。该集合将保存从控制器中的视图传递的所有数据。您可以使用调试器来探索发送给控制器的数据。
#2
0
Why dont you just change the action to accept your model?
你为什么不改变行动,接受你的模特呢?
Something like this:
是这样的:
public ActionResult SaveQuote(ModelType model)
{
objQuote.Quote_Currency = model.Quote_Currency;
dcfx.FxQuotes.InsertOnSubmit(model.Quote);
dcfx.SubmitChanges();
return View();
}
Alternatively you can change it to accept a form collection as mentioned in another answer:
您也可以将其更改为接受另一个答案中提到的表单集合:
public ActionResult SaveQuote(FormCollection collection)
Hope this helps
希望这有助于
#1
1
You can add a FormCollection collection
as an extra parameter to your controller method. That collection will hold all data passed from the view in the controller. You can use the debugger to explore which data is exactly being sent to the controller.
您可以添加一个FormCollection集合作为控制器方法的额外参数。该集合将保存从控制器中的视图传递的所有数据。您可以使用调试器来探索发送给控制器的数据。
#2
0
Why dont you just change the action to accept your model?
你为什么不改变行动,接受你的模特呢?
Something like this:
是这样的:
public ActionResult SaveQuote(ModelType model)
{
objQuote.Quote_Currency = model.Quote_Currency;
dcfx.FxQuotes.InsertOnSubmit(model.Quote);
dcfx.SubmitChanges();
return View();
}
Alternatively you can change it to accept a form collection as mentioned in another answer:
您也可以将其更改为接受另一个答案中提到的表单集合:
public ActionResult SaveQuote(FormCollection collection)
Hope this helps
希望这有助于