如何将模型存储到变量 [英] How To store a model to variabel
本文介绍了如何将模型存储到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的模型存储到变量中,以便我可以在控制器中使用它
这里我的视图,
I want to store my model in view to variable so I can use that in controller
here my view,
<div class="form-group">
@Html.LabelFor(model => model.id_perusahaan, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("id_perusahaan", String.Empty)
@Html.ValidationMessageFor(model => model.id_perusahaan)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.total_card, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.total_card)
@Html.ValidationMessageFor(model => model.total_card)
</div>
</div>
我想存储在var Perusahaan和var total
i试试:
I want to store in var Perusahaan and var total
i was try :
var total= model => model.total_card;
var Perusahaan =model => model.id_perusahaan
但不起作用
but its not work
推荐答案
如果您希望在提交表单时保留您的模型属性然后他们需要在一个表格领域。如果您不希望它们显示,则使用Html.HiddenFor(m => m.YourProperty)将它们存储在隐藏字段中
至于下拉菜单,谷歌如何要在mvc中做下拉列表,那里有很多例子。
If you want your model properties to be kept when the form is submitted then they need to be in a form field. If you don't want them displayed then store them in a hidden field using Html.HiddenFor(m => m.YourProperty)
As for dropdowns, google how to do dropdowns in mvc, there are lots of examples out there.
这篇关于如何将模型存储到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文