我正在将模型传递给单选按钮,如何将其设为默认模型?
将模型传递给具有三个不同值的单选按钮,例如
<%: Html:RadioButtonListFor(model=>model.Country, Model.Countries, new {@class="countrytype"})%>
这些国家有三个值:US、Canada、Other。但我希望默认选择美国。我怎么能这么做呢?
我的actionresult是:
public ActionResult Select(CountryModel m) { ... return View( new CountryModel (countrytype.AsQuicklist()); 如何
在返回视图中添加模型参数?
passing a model to radiobutton which has three different values for example
<%: Html:RadioButtonListFor(model=>model.Country, Model.Countries, new {@class="countrytype"})%>
these countries has three values U.S, Canada, Other. But i want U.S to be selected by default. How can my do that?
my actionresult is :
public ActionResult Select(CountryModel m)
{ ... return View( new CountryModel ( countrytype.AsQuicklist());
}
how can i add model parameter in the return view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RadioButtonListFor
不是 ASP.NET MVC 中包含的标准帮助程序。因此,这个问题的答案将取决于您从哪里获得这个助手以及它是如何实现的。因此,盲目尝试:您可以尝试将控制器操作中相应的模型属性设置为您想要预选的按钮的值:
RadioButtonListFor
is not a standard helper included in ASP.NET MVC. So the answer to this question will depend on where did you get this helper from and how it is implemented.So a shot in the dark: you could try setting the corresponding model property in your controller action to the value of the button you want preselected: