Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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# 在MVC中的RadioButton上回发_C#_Asp.net Mvc_Radiobuttonfor - Fatal编程技术网

C# 在MVC中的RadioButton上回发

C# 在MVC中的RadioButton上回发,c#,asp.net-mvc,radiobuttonfor,C#,Asp.net Mvc,Radiobuttonfor,我的mvc网页中有两个单选按钮 <% using (Html.BeginForm("Search", "Search")) { %> // some html codes <%= Html.RadioButtonFor(m => m.Agents, "A", new { Checked = "checked" })%> //radio button 1 <%= Html.RadioBu

我的mvc网页中有两个单选按钮

 <% using (Html.BeginForm("Search", "Search"))
   { %>
  // some html codes
     <%= Html.RadioButtonFor(m => m.Agents, "A", new { Checked = "checked" })%> //radio button 1                     
      <%= Html.RadioButtonFor(m=> m.Agents,"AG") %>  //radio button 2                      
  // some html codes
   <% } %>

//一些html代码
m、 代理,“A”,新建{Checked=“Checked”})%>//单选按钮1
m、 代理,“AG”)%>//单选按钮2
//一些html代码
aspx页面如下所示

我的页面中也有一个按钮。如果我点击该按钮,则会发生回发


如果我更改了单选按钮的选择,我需要再次回发。如何对该事件进行回发。但如果我更改单选按钮的选择,则不会进行回发。如何实现这一点?

您需要使用javascript来实现这一点。当用户更改单选按钮的选择时,不会发生服务器端事件。因此,如果您使用jquery,您可以订阅活动并提交表单:

<% using (Html.BeginForm("Search", "Search", FormMethod.Post, new { id = "myform" })) { %>
    <%= Html.RadioButtonFor(m => m.Agents, "A", new { @checked = "checked", @class = "radio" }) %>
    <%= Html.RadioButtonFor(m => m.Agents, "AG", new { @class = "radio" }) %>
<% } %>

这是使用单选按钮执行回发的一种方法:

<label>@Html.RadioButton("Buyer", "Buyer", new { onchange = "this.form.submit();" })Buyer</label>
@Html.RadioButton(“买方”,“买方”,新的{onchange=“this.form.submit();”)买方
<label>@Html.RadioButton("Buyer", "Buyer", new { onchange = "this.form.submit();" })Buyer</label>