Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取asp.net mvc Html.RadioButton的选定值_C#_.net_Asp.net Mvc - Fatal编程技术网

C# 如何获取asp.net mvc Html.RadioButton的选定值

C# 如何获取asp.net mvc Html.RadioButton的选定值,c#,.net,asp.net-mvc,C#,.net,Asp.net Mvc,我有两个单选按钮 <%= Html.RadioButtonFor(m =>m.Type,true,new {id = "rdPageType",CHECKED = "checked" }) %> <%= Html.RadioButtonFor(m =>m.Type,true,new {id = "rdPageType12",CHECKED = "checked" }) %> m.Type,true,新的{id=“rdPageType”,CHECKED=“CH

我有两个单选按钮

<%= Html.RadioButtonFor(m =>m.Type,true,new {id = "rdPageType",CHECKED = "checked" }) %>
<%= Html.RadioButtonFor(m =>m.Type,true,new {id = "rdPageType12",CHECKED = "checked" }) %>
m.Type,true,新的{id=“rdPageType”,CHECKED=“CHECKED”}]>
m、 Type,true,新的{id=“rdPageType12”,CHECKED=“CHECKED”})%>
如何检查选择了哪一个,当选择第一个时,我应该能够将“rdPageType”的布尔值设置为true,将另一个设置为false,反之亦然


请提供帮助

假设您有以下型号:

public class MyModel
{
    public bool RdPageType { get; set; }
}
您的控制器可能如下所示:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        // Action to render the form, initialize the model
        // with some default value
        var model = new MyModel
        {
            RdPageType = true
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(MyModel model)
    {
        // Action called when the form is posted
        // model.RdPageType will depend on the radio
        // being selected
        return View(model);
    }
}
以及以下观点:

<% using (Html.BeginForm()) { %>
    <%= Html.RadioButtonFor(m => m.RdPageType, true, new {id = "rdPageType" }) %>
    <%= Html.RadioButtonFor(m => m.RdPageType, false, new {id = "rdPageType12" }) %>    
    <input type="submit" value="OK" />
<% } %>

m、 RdPageType,true,新的{id=“RdPageType”})%>
m、 RdPageType,false,新建{id=“rdPageType12”})%>

感谢您为Darin付出的努力。我有个问题。我有两个单选按钮,如上所述,我有两个值,例如,Radiobutton1:Chocolate Radiobutton2:Milk,这里我选择“Chocolate”。我需要在“如果”循环中检查我选择的单选按钮,并将一些相关数据插入到te DB。例如,如果我选择'chocolate',我应该将字符串'chocolate'插入DB Table列,如果选择'milk',则将字符串thn milk插入该列。你能帮我解决这个问题吗。万分感谢