logo
down
shadow

Passing selected value from the radio buttons to the controller in MVC


Passing selected value from the radio buttons to the controller in MVC

By : jim_block
Date : November 18 2020, 11:13 AM
To fix this issue I'm trying to pass this selected radio button value from the razor view to the controller.... can someone please give me an idea how to do this?..................... My View looks like this: , Add property:
code :
public string SelectedAnswer { get; set; }
@Html.RadioButtonFor(m => m.SelectedAnswer, "Answer1")
@Html.RadioButtonFor(m => m.SelectedAnswer, "Answer2")
@Html.RadioButtonFor(m => m.SelectedAnswer, "Answer3")
@Html.RadioButtonFor(m => m.SelectedAnswer, "Answer4")


Share : facebook icon twitter icon
JQUERY 2 groups of radio buttons with labels - hidden radio buttons - 1 selected 1 doesn't get selected

JQUERY 2 groups of radio buttons with labels - hidden radio buttons - 1 selected 1 doesn't get selected


By : Yutiya Meone
Date : March 29 2020, 07:55 AM
this will help Markup is the culprit:
IDs must be unique Radio groups must have unique name attributes
code :
 <div id="sites2">
    <input type="radio" name="site2" id="so2" value="stackoverflow" /><label for="so2"><img src="http://sstatic.net/stackoverflow/img/favicon.ico" alt="Stack Overflow" /></label>
    <input type="radio" name="site2" id="sf2" value="serverfault" /><label for="sf2"><img src="http://sstatic.net/serverfault/img/favicon.ico"alt="Server Fault" /></label>
    <input type="radio" name="site2" id="su2" value="superuser" /><label for="su2"><img src="http://sstatic.net/superuser/img/favicon.ico" alt="Super User" /></label>
</div>
Passing of values of selected radio buttons which are added dynamically by a servlet to a jsp

Passing of values of selected radio buttons which are added dynamically by a servlet to a jsp


By : gzzing
Date : March 29 2020, 07:55 AM
Does that help Place all of your radio buttons within a form that submits to your servlet. Make sure that each of your radio buttons name attributes is set to the same value. Also set the value attribute of each radio button to its respective id. When your form submits, it will pass the value of the selected radio button to the servlet. You can then retrieve the value using request.getParameter().
For more information review this tutorial. http://www.roseindia.net/jsp/radio-button-jsp.shtml
Passing Multiple Radio buttons value from Visual force page to controller

Passing Multiple Radio buttons value from Visual force page to controller


By : newone
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am using Page block table on visual force page and each row has radio buttons , i want to pass the value of each selected radio button , from each row on visual force page to apex Controller class. , I suggest you add a new custom field, like SelectedAnswer, change
code :
apex:selectRadio value="{!selectedAnswer}">
apex:selectRadio value="{!sq.SelectedAnswer__c}">
public PageReference SubmitSurvey() {

// Multiple Checkbox value Logic Goes Here
foreach (SurveyQuestionsType sqItem : getSurveyQuestions()) {
if(sqItem.SelectedAnswer__c == 'yes'){

           //Inserting The Survey Result

           tblSurveyResult__c SurveyResult = new tblSurveyResult__c(
                  Name = sqItem.SelectedAnswer__c,
                  Answer__c = 1
                 );
           insert SurveyResult;


    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Survey Submitted Successfully'));

} else if (sqItem.SelectedAnswer__c == 'no'){

    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,sqItem.SelectedAnswer__c));

} else {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Atleast one value'));
}
}
return null;
}
Passing the value of selected radio buttons from one jsp to another

Passing the value of selected radio buttons from one jsp to another


By : Jhonathan Ramirez
Date : March 29 2020, 07:55 AM
I hope this helps . try following in Result jsp code. you will get the correct radio value.
code :
<%
String id[]= new String [5];
for (int i=1;i<5; i++)
{
   if(request.getParameter("a"+i)!=null){
    id[i]=request.getParameter("a"+i);
    out.println(id[i]);
  }
}

%>
Passing the selected Radio button value to Controller C# MVC

Passing the selected Radio button value to Controller C# MVC


By : Petre
Date : March 29 2020, 07:55 AM
it should still fix some issue Rather than passing single string argument, you can try to create a viewmodel that stores both of selected value and radio button items. Here is example of proper viewmodel setup:
code :
public class ViewModel
{
    // since the CustID is numeric, I prefer using 'int' property
    public int IsSelected { get; set; }

    public List<Customer> Customers { get; set; }

    // other properties
}
@model ViewModel

@using (Html.BeginForm("AddCustomerLinkToDB", "Admin", FormMethod.Post))
{
    <table class="table table-bordered table-hover">
        <tr>
            <th>Customer ID</th>
            <th>Customer Name</th>
            <th>Select this user</th>
        </tr>
        @foreach (var item in Model.Customers)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Name</td>
                <td>@Html.RadioButtonFor(model => model.IsSelected, item.Id, new { id = item.Id })</td>
            </tr>
        }
    </table>
}
[HttpPost]
public ActionResult AddCustomerLinkToDB(ViewModel model)
{
    int selectedCustomer = model.IsSelected;
    // other stuff

    return View();
}
Related Posts Related Posts :
  • Ninject dependency injection: Read bindings from config?
  • Creating Custom Authorization Attribute with MVC
  • How to use c# inside mvc razor pages
  • Reasons not to increase maxQueryStringLength?
  • asp.net mvc exclude an action from search engine crawling
  • Best Way to reuse code inside my Controller action method
  • BEM and asp.net mvc
  • RazorPDF save pdf file to server directory in MVC4
  • Controller Unit Testing with model validation
  • How to bind input field to editfor model MVC
  • How can I restrict access to a view only to two specific users each time in MVC?
  • How to modify CRUD operations with Entity Framework in .NET MVC application
  • ModelBinding Issue with a Struct
  • issue in adding elements into a list in mvc
  • IActionFilter class can only find physical attributes, not ones added in GlobalFilters config
  • ASP.NET MVC Bug with Model Binding: "Specified cast is not valid" when no data provided for dictionary
  • How to reuse class in models without using validation for all of them
  • How to set routing to have some controller actions handled by angular
  • ads while debugging mvc website
  • Does editing a Web.config file trigger an overlapping recycle or a start+stop of the application pool?
  • How can i delete multi selected records using checkbox in Kendo Grid?
  • 404.15 not found MVC4 RazorJS
  • TFS:The "Microsoft.Reporting.RdlCompile" task could not be loaded from the assembly Microsoft.ReportViewer.Web
  • ViewModel in postback to controller is null
  • Get the user id of a username identity 2.0
  • Don't validate date fields on MVC
  • Add class and default value to MVC dropdown that isn't linked to model
  • Passing values from the view to the controller in MVC
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org