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 8070139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:17:58+00:00 2026-06-05T13:17:58+00:00

I want to create an ‘editable’ table in MVC, where each row will have

  • 0

I want to create an ‘editable’ table in MVC, where each row will have its own dropdownlist to update the row value. How do I set the dropdownlist selected value on page load for rows that were already updated before.

My current Razor code is like this:

<tbody>
   @foreach (var conversion in Model.PaginatedConversions)
   {
        <tr>
             <td>@conversion.tSystem.systemName</td>
             <td>@conversion.conversionStandardValue</td>
             <td>@Html.DropDownList("ConversionStandardIdFor" + conversion.conversionID.ToString(), Model.AvailableValuesForConversion, "")</td>
             <td>@conversion.conversionDescription</td>
             <td>@conversion.conversionDateInput</td>
             <td>@conversion.ConversionDateConverted</td>
             <td>@conversion.ConversionUser</td>
        </tr>
   }

But I cannot set the selected value of each dropdown. How can I do this? Thanks for the help!

Edit1 : This code loops a model property (Model.PaginatedConversions), which is of type List<Conversion>. The Conversion class is as followed:

public class Conversion {
    int ConversionId { get;set; }
    string ConversionValue { get; set; }
    int ConversionConvertedValue { get; set; }
}

The goal of the table is to create editable rows for user to map the ConversionValue to another value that can be selected in Model.AvailableConversionValues. This converted value will be stored in ConversionConvertedValue.

The property Model.AvailableConversionValues are of type List<SelectListItem> that contains the available values user can choose from to map the ConversionValue.

  • 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-05T13:18:01+00:00Added an answer on June 5, 2026 at 1:18 pm

    Passing the ConversionValue as a name didn’t work. I created another method in the ViewModel, and use that instead for getting the SelectListItem, passing the selected value to be selected in the ListItem.

    <td>@Html.DropDownList("ConversionFor" + conversion.conversionID.ToString(), Model.GetAvailableConversionValues(conversion.conversionStandardID))</td>
    

    And in the ViewModel I have this method:

    public List<SelectListItem> GetAvailableConversionValues(int? selectedValue)
        {
            if (selectedValue != null)
            {
                SelectListItem selectItem = AvailableValuesForConversion.Where(t => int.Parse(t.Value) == selectedValue).SingleOrDefault();
    
                if (selectItem != null)
                {
                    selectItem.Selected = true;
                }
            }
            return AvailableValuesForConversion;
        }
    

    Thanks for the help!

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

Sidebar

Related Questions

say, I have a table TABLE(col1,col2,col3) and, I want create a index INDEX(col1=table.col1+table.col2)
I want create a project where every user can have his own 'homepage'. So
I have row f . I want create matrix R such that every row
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
In C# code, I want create a log file for each each method in
I want create a tarball that when extracted the file(s) will be placed at
I want create own SetupTypeDlg using wix default dialogs to show the disk costs
I want create constructor that will take one or more integers and save it
I want create object from Canvas3D class(in java) but my Compiler doesn't have this

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.