Home > ASP.NET MVC > ASP.NET # MVC # 6 – ASP.NET MVC RadioButton(List)[Check/Uncheck ASP.NET MVC Radiobutton from controller and call OnClick event on it]

ASP.NET # MVC # 6 – ASP.NET MVC RadioButton(List)[Check/Uncheck ASP.NET MVC Radiobutton from controller and call OnClick event on it]

Hi Geeks,

Today we will see following things regarding ASP.NET MVC RadioButton

1) How to check/uncheck specific radio button in the list of two radio buttons (e.g.image )

2) To call the JavaScript method on onClick event of it.

image

Example:

Step I

We have a class Employee_Details as follows.

   public classEmployee_Gender   {
       public int Gender { get; set; }
   }

 

Step II

We take one strongly typed view named it as Employee inheriting the class Employee_Gender created above.

In the following view ,

We have two Radio buttons we call a java script method  onRadioClick on its onClick event. 

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Radio.Models.clsEmployee>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  
Male <%:Html.RadioButtonFor(c => c.Gender, 0, new { @onClick = "onRadioClick(this);" })
%>
    Female <%:Html.RadioButtonFor(c => c.Gender, 1, new { @onClick = "onRadioClick(this);" })
%>

    <script type="text/javascript">
        function
onRadioClick(e) {           
            alert(e.value);       
        }
    </script
>
</
asp:Content
>

Step III

In the Controller we will right one method called GetEmoloyee ,

The return type of the following method is ActionResult , so it will return the model to the view defined above named as Employee.

public ActionResult GetEmployee()
      {

           Radio.Models.clsEmployee obj = new Radio.Models.clsEmployee();
           obj.Gender = 1;
           return View("Employee",obj);

      }

 

When you click on the radio buttons you will have output as

0 for male and 1 for female respectively

     image

 

For More information on  ASP.NET MVC DropdDownlist Control refer link ASP.NET MVC DropDownlist.

For More on Microsoft technologies visit our site Dactolonomy of WebResource

 

Thank you.

Advertisements
Categories: ASP.NET MVC
  1. May 14, 2013 at 2:31 am

    With internet radio, you get pretty much what you want, when you want.
    As an Internet broadcaster, it is high time that you pick
    on these available opportunities and add that $ilver
    sheen to your broadcasting happiness. This powerful and versatile
    solution is also available in three different versions, so you should have no trouble finding the perfect
    one for you.

  2. May 14, 2013 at 2:31 am

    For many regions, the entire rpm distributed free
    of charge STB The costs have been overwhelmed, and then implementation of
    the Reconstruction of two-way network, the
    funding is clearly beyond its capability. There are hundreds of people working in
    foreign aid missions, expats, Peace Corps, and others in relief and business sectors.

    This powerful and versatile solution is also available in three different versions, so you should have no
    trouble finding the perfect one for you.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: