开发者

MVC VB.NET: Trying to reference a radiobutton value by passing it as byval param in action?

开发者 https://www.devze.com 2023-01-19 06:06 出处:网络
RB: <input type=\"radio\" onclick=\"accountShow()\"runat=\"server\" name=\"GuestAccount\" class=\"GuestAc开发者_如何学Pythoncount\" value=\"1\" />

RB:

<input type="radio" onclick="accountShow()"  runat="server" name="GuestAccount" class="GuestAc开发者_如何学Pythoncount" value="1" />


<input type="radio" onclick="accountShow()"  runat="server" name="GuestAccount" class="GuestAccount" value="0" />

Action:

Public Function Edit(ByVal guestAccount As String) As ActionResult

However I am receiving a null value


You should not be declaring server controls there; remove the runat="server" and I think it should work. Making them ASP.NET server controls means that the actual name/id will be something different, so MVC won't find it.

Generally, you don't use server controls in MVC.


You could use MVC helper methods to render your radiobutton controls in your view which should fix your issue:

<%=Html.RadioButton("GuestAccount", "0", new { @class = "GuestAccount", onclick = "AccountShow()" }) %>
<%=Html.RadioButton("GuestAccount", "1", new { @class = "GuestAccount", onclick = "AccountShow()" }) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消