有没有绑定复杂对象单选按钮的方式 [英] Is there a way to bind a complex object to radiobutton
问题描述
我有我从我的模型是这样产生单选按钮的列表:
I have a list of radiobuttons that I am generating from my model like this:
@foreach (var offer in Model.AvailableOffers)
{
<div>
@Html.RadioButtonFor(m => m.selectedAvailableOffer, offer)
@Html.Label(offer.begin_date.Month + "/" + offer.begin_date.Day + " - " + offer.end_date.Month + "/" + offer.end_date.Day + ", " + offer.offer_name)
</div>
}
型号包括以下:
public List<AvailableOffer> AvailableOffers { get; set; }
public AvailableOffer selectedAvailableOffer { get; set; }
看我如何我尝试后我的报价
对象回到我在 RadioButtonFor
方法控制?这显然是不工作的,但它是我想要完成的任务。有什么办法后选择报价
对象回我的控制器的全还是我坚持加入一些身份证到我的对象,只回发的ID作为这里建议
See how I am trying to post my offer
object back to my controller in the RadioButtonFor
method? This is obviously not working, but it's what I want to accomplish. Is there any way to post the whole selected offer
object back to my controller or am I stuck adding some sort of ID to my object and only posting back the ID as is suggested here:
<一个href=\"http://stackoverflow.com/questions/5768274/correct-way-to-bind-an-mvc3-radiobutton-to-a-model\">Correct绑定一个MVC3单选一个模型方式
推荐答案
不久:不,你不能将整个'报价'对象回服务器。这是更好地在客户端只使用的ID。
如果你真的想回来后整体报价可以使用某种类型的序列化将数据从每个报价对象单选按钮的值存储。
Shortly: No, you can't pass whole 'offer' object back to the server. It's better to use only id's on the client side. If you realy want to post back whole offer you can use some kind of serialization to store data from each offer object as a value of radiobutton.
这篇关于有没有绑定复杂对象单选按钮的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!