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

  • Home
  • SEARCH
  • 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 8494097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:12:22+00:00 2026-06-10T23:12:22+00:00

When I show a list of testplanViewModels in my View and the user selects

  • 0

When I show a list of testplanViewModels in my View and the user selects one the SelectedTestplanId is returned to the Controller post action. What should also be returned is the TemplateId which belongs to the SelectedTestplanId.

When the AutoMapper definition is run the Testplan.TestplanId is implicitly copied over to the TestplanViewModel.TestplanId. The same could be done by providing a TemplateId on the TestplanViewModel. When the user selects now a “TestplanViewModel” in the View, how can I attach the TemplateId to the controller action to access it there? The DropDownList does not allow 2 dataValueFields!

CreateMap<Testplan, TestplanViewModel>().ForMember(dest => dest.Name, opt => opt.MapFrom(src => string.Format("{0}-{1}-{2}-{3}", src.Release.Name, src.Template.Name, src.CreatedAt, src.CreatedBy)));

public ActionResult OpenTestplanViewModels()
{
    IEnumerable<Testplan> testplans = _testplanDataProvider.GetTestplans();          
    var viewModel = new OpenTestplanViewModel
    {
        DisplayList = Mapper.Map<IEnumerable<Testplan>, IEnumerable<TestplanViewModel>>(testplans)
    };
    return PartialView(viewModel);
}


public class TestplanViewModel
{      
    public int TestplanId { get; set; }     
    public string Name { get; set; }           
}


public class OpenTestplanViewModel
{
    [Required(ErrorMessage = "No item selected.")]
    public int SelectedTestplanId { get; set; } 
    public IEnumerable<TestplanViewModel> DisplayList { get; set; }       
}

OpenTestplanViewModel

@using (Html.BeginForm("Open", "Testplan"))
{ 
    @Html.ValidationSummary(false)      
    @Html.DropDownListFor(x => x.SelectedTestplanId, new SelectList(Model.DisplayList, "TestplanId", "Name"), new { @class = "listviewmodel" })  
}

Solution:

 public class OpenTestplanViewModel
    {
        [Required(ErrorMessage = "No item selected.")]
        public string TestplanIdAndTemplateId { get; set; } 
        public IEnumerable<TestplanViewModel> DisplayList { get; set; }

        public int SelectedTestplanId
        {
            get
            {
                return Convert.ToInt32(TestplanIdAndTemplateId.Split(new[] { '_' }).First());
            }
        }
        public int SelectedTemplateId
        {
            get
            {
                return Convert.ToInt32(TestplanIdAndTemplateId.Split(new[] { '_' }).Last());
            }
        }   
    }

 CreateMap<Testplan, TestplanViewModel>()
                .ForMember(d => d.Name, o => o.MapFrom(src =>  string.Format("{0}-{1}-{2}-{3}", src.Release.Name, src.Template.Name, src.CreatedAt, src.CreatedBy)))
                .ForMember(d => d.TestplanIdAndTemplateId, o => o.MapFrom(src => src.TestplanId + "_" + src.TemplateId));
  • 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-10T23:12:23+00:00Added an answer on June 10, 2026 at 11:12 pm

    HTML doesn’t really work that way. If you want more than one value returned from the post for the dropdown (the helper generates a select element), you’ll have to create a property on your view model that you then parse within the controller.

    For instance, if you had two integer ID fields, the combined property could create a value that looks something like 23_42. You could then use the Split method to get the correct values (23 & 42) back.

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

Sidebar

Related Questions

Design requirement: Show a list of items the user can pick from After having
I want to show a list of options to the user when he/she clicks
i am developing one app in which i need to show list of product
I want to show list of products in ListView where one of the columns
I have to show list view as like below image Here I have the
I have one JTable which show list of book and it can be filtered
I have list of users on my View: foreach (var user in (List<GetWorkDone.Model.Accounts.User>)ViewBag.users) {
Is it possible to sort div layers? Examples only show list items being sorted.
Im tring to show a list of articles on my site with a authour,
Basically i wanna show total list items for each list item that contains sub

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.