Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:17:03+00:00 2026-06-10T01:17:03+00:00

I have a problem on passing values from view to controller Here is my

  • 0

I have a problem on passing values from view to controller

Here is my view:

 @model  IEnumerable<SQLOperation.Models.QuestionClass.Tabelfields>

@{
     ViewBag.Title = "Question";
 }

 <h3> Question</h3>

 @{int i = 0;}

 @foreach (var item  in Model)
 {

  using (Html.BeginForm("Question", "Home"))
  {
      @Html.DisplayFor(modelItem => item.QuestionName)
      @Html.HiddenFor(m => item.QuestionID)      
         <br /><br />   
      if (item.Option1 != "")
      {
        @Html.RadioButtonFor(m => item.SelectedOption, item.Option1, item)                
        @Html.DisplayFor(modelItem => item.Option1)
                    <br /><br />                
      }

      if (item.Option2 != "")
      {
         @Html.RadioButtonFor(m => item.SelectedOption, item.Option2, item)              
         @Html.DisplayFor(modelItem => item.Option2)
                    <br /><br />
      }

      if (item.Option3 != "")
      {           
        @Html.RadioButtonFor(m => item.SelectedOption, item.Option3, item)              
        @Html.DisplayFor(modelItem => item.Option3)
                    <br /><br />
      }


      if (item.Option4 != "")
      {
       @Html.RadioButtonFor(m => item.SelectedOption, item.Option4, item)             
                    @Html.DisplayFor(modelItem => item.Option4) 
                <br /><br />     
      }
      i = (Int16)i + 1;


      if (Model.Count() == i)
      {
                <input name="btnsumbit" type="submit" value="Submit Feedback" 
                style="font-family:Segoe UI Light;font-size:medium;"/>
      }
  }
 }

My controller :

[HttpGet]
    public ActionResult Question(string email)
    {
        var tf = new QuestionClass.Tabelfields();

        IList<QuestionClass.Tabelfields> viewmodel = new List<QuestionClass.Tabelfields>();
        var q = QuestionClass.getallQuestion(email).ToList();

        foreach (SQLOperation.Models.Question item in q)
        {
            QuestionClass.Tabelfields viewItem = new QuestionClass.Tabelfields();

            viewItem.Email = item.Email;
            viewItem.QuestionID = item.QuestionID;
            viewItem.QuestionName = item.QuestionName;
            viewItem.Option1 = item.Option1;
            viewItem.Option2 = item.Option2;
            viewItem.Option3 = item.Option3;
            viewItem.Option4 = item.Option4;                
            viewmodel.Add(viewItem);
        }
         return View(viewmodel);
    }

    [HttpPost, ActionName("Question")]
    public void Question(IEnumerable<QuestionClass.Tabelfields> items)
    {

    }

My Model:

public class QuestionClass
{
    public static FeedbackDatabaseDataContext context = new FeedbackDatabaseDataContext();

    public class Tabelfields : Question
    {
        //public decimal QuestionID { get; set; }
        //public string Email { get; set; }
        //public string QuestionName { get; set; }
        //public string Option1 { get; set; }
        //public string Option2 { get; set; }
        //public string Option3 { get; set; }
        //public string Option4 { get; set; }
        public string SelectedOption { get; set; }
    }


    public static List<Question> getallQuestion(string email)
    {
        var list = (from q in context.Questions where q.Email == @email select q);

        return list.ToList();
    }
 }

however I get NULL in “items” in controller.

[HttpPost, ActionName("Question")] 
    public void Question(IEnumerable<QuestionClass.Tabelfields> items) 
    { 
    }

Whereas if I change my View & Controller to below , I get last value from database in controller

View:

@foreach (var item in Model)
{
  using (Html.BeginForm("Question", "home", new { email=item.Email,  q=item.QuestionID}))
  {
      @Html.DisplayFor(modelItem => item.QuestionName)
      @Html.HiddenFor(m => item.QuestionID)
       .

       .

       .
       . 
  }
}

Controller:

[HttpPost, ActionName("Question")] 
    public void Question(string email,int q) 
    {   
    }

I get values in email and q

so how can I get all values i.e. QuestionId,Email,Questionname and it’s appropriate selected value (radiobutton) in controller ?

i.e. in Following Controller:

[HttpPost, ActionName("Question")] 
    public void Question(IEnumerable<QuestionClass.Tabelfields> items) 
    { 
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:17:04+00:00Added an answer on June 10, 2026 at 1:17 am

    You need to index the Html.*For items as such;

    @Html.RadioButtonFor(m => m[i].SelectedOption, item.Option3, item)
    

    To make things simplier, i’d probably get rid of the foreach & and separate i declaration and use the following;

    @for(int i=0; i < Model.Count; i++)
    {
        @Html.HiddenFor(m => m[i].QuestionID) 
        @Html.RadioButtonFor(m => m[i].SelectedOption, Model[i].Option3, Model[i])
    }
    

    etc.

    Indexing like this will cause the html to be rendered with the indexing intact:

    <input type='hidden' name=[0].'QuestionId' />
    <input type='hidden' name=[1].'QuestionId' />
    <input type='hidden' name=[2].'QuestionId' />
    

    Rather than what you’re doing currently, which ends up rendering as so;

    <input type='hidden' name='QuestionId' />
    <input type='hidden' name='QuestionId' />
    <input type='hidden' name='QuestionId' />
    

    Without the indexing, each form field is given the same name, so you’re controller is going to think only one was returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with passing values from model to controller, let's say i
I have a problem in passing a value from controller to view In controller,
I seem to have a problem passing some strings on from one form to
I am having a problem with views. I have a view and am passing
Here is my problem. I have a list of models that are displayed to
Here is my problem. I have a list of models that are displayed to
I have a problem with passing of an array from Fortran to a c
i have problem passing data from one page to another using GET, for example
I have problem on passing jquery variable on codeigniter controller. actually i want to
I have a problem where I need values passed in from a GET request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.