[记录]ASP.NET MVC 2.0 如何使用Html.RadioButtonFor?
在MVC 2.0里支持强类型实体绑定,可以直接使用如
<%: Html.TextBoxFor(model => model.Description, new { @class="text"})%>
来自动将实体绑定到表单里,但我不知道如何使用 Html.RadioButtonFor 来生成 RadioButton ? 在使用 Html.RadioButtonFor 必须至少2个参数,另一个是指一个object,我绑定的字段是一个bool型的,如何能自动生成相关的RadioButton 呢?
开始时一直觉得一句话就可以完成,弄了半天也没成功,后来想起了其实调用一次 Html.RadioButtonFor 就只生成一个 RadioButton,那又怎么可能一句就生成2个button呢?呵,傻了吧,唉,其实只要分别调用2次就可以了啊,然后再加上个 if 判断一下当前值即可,以下是实现的代码:
<%if(Model.OffStatus){ %>
<%: Html.RadioButtonFor(model => model.OffStatus, true, new { @id = "radio1", @name = "Status", @checked="checked" })%>
<label for="radio1">开启</label>
<%: Html.RadioButtonFor(model => model.OffStatus, false, new { @id = "radio2", @name = "Status" })%>
<label for="radio2">关闭</label>
<%}else { %>
<%: Html.RadioButtonFor(model => model.OffStatus, true, new { @id = "radio1", @name = "Status" })%>
<label for="radio1">开启</label>
<%: Html.RadioButtonFor(model => model.OffStatus, false, new { @id = "radio2", @name = "Status", @checked = "checked" })%>
<label for="radio2">关闭</label>
<%} %>
[记录]ASP.NET MVC 2.0 如何使用Html.RadioButtonFor?的更多相关文章
- Profession ASP.NET MVC 2.0 NerdDinner示例可运行源码
最近一段时间在看JonGalloway等著作的<Profession ASP.NET MVC 2.0>.本书并没有按照常规的大部头书籍那样,按部就班的介绍MVC的概念等,而是在第一章直接引 ...
- ASP.NET MVC 4.0中选择Windows 验证默认出错拒绝访问的原因和解决方案
在VS 2012或者2013 中,根据模板创建一个ASP.NET MVC 4.0的应用程序,选择下面的模板 然后选择Intranet Application 不对源代码做任何修改,直接按下F5调试,会 ...
- 安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题
安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x80070643) ...
- (转)ASP.NET Mvc 2.0 - 1. Areas的创建与执行
转自:http://www.cnblogs.com/terrysun/archive/2010/04/13/1711218.html ASP.NET Mvc 2.0 - 1. Areas的创建与执行 ...
- 返璞归真 asp.net mvc (13) - asp.net mvc 5.0 新特性
[索引页][源码下载] 返璞归真 asp.net mvc (13) - asp.net mvc 5.0 新特性 作者:webabcd 介绍asp.net mvc 之 asp.net mvc 5.0 新 ...
- ASP.NET MVC 3.0 Controller基础
ASP.NET MVC 3.0 Controller基础 1.Controller类与方法 Controller(控制器)是ASP.NET MVC的核心,负责处理浏览器请求,并作出响应.Cotro ...
- 从零开始学习ASP.NET MVC 1.0
转自:http://www.cnblogs.com/zhangziqiu/archive/2009/02/27/ASPNET-MVC-1.html <从零开始学习ASP.NET MVC 1.0& ...
- ASP.NET MVC 4.0的Action Filter
有时候你想在调用action方法之前或者action方法之后处理一些逻辑,为了支持这个,ASP.NET MVC允许你自定义创建action过滤器.Action过滤器是自定义的Attributes,用来 ...
- 安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x80070643), "安装时发生严重错误 " (Ela)
原文:安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x800706 ...
随机推荐
- HTML 表单
HTML 表单包含表单元素. <form> 元素定义 HTML 表单 表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. HTML 表单用于搜集不同类型的用户输入 ...
- arcmap Command
The information in this document is useful if you are trying to programmatically find a built-in com ...
- SharePoint 判断用户是否在字段"人员和组"里面
两个自己平时写的方法,记录下来,方便以后查找使用: 1.判断用户是否在字段人员和组里面: public static bool IsUserInFiled(int UserID, string Lis ...
- Understanding theory (1)
Source: verysmartbrothas.com It has been confusing since my first day as a PhD student about theory ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q49-Q51)
Question 49You are designing a SharePoint 2010 intranet site for a corporation. Your design must mee ...
- PULL解析XML的运行机制详解
PULL解析简单易上手,基本上看一遍,基本上就会解析啦,但总是感觉对PULL解析的运行机制不是很了解,就总结了以下事件驱动到底是怎么执行的.. PULL: Android内置了PULL解析器.PULL ...
- 工作中碰到的js问题(disabled表单元素不能提交到服务器)
今天碰到一个奇葩的问题,asp页面表单提交后,有一个文本框<input type="text" name="phone" id="phone&q ...
- iOS 单例传值遇见问题
单例模式的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 1.单例模式的要点: 显然单例模式的要点有三个:一是某个类只能有一个实例: ...
- iOS 开发之路(使用WKWebView加载Html5) 四
基于Swift 3 . Xcode 8 . iOS 10 下的WKWebView的使用. 首先是WKWebView的基本用法: var wk:WKWebView! var progBar:UIProg ...
- OS开发UI篇—使用UItableview完成一个简单的QQ好友列表
本文转自:http://www.cnblogs.com/wendingding/p/3763330.html 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableVi ...