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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:30:45+00:00 2026-06-15T19:30:45+00:00

I am trying to pass a SelectListItem to a view. This checkbok list will

  • 0

I am trying to pass a SelectListItem to a view. This checkbok list will be viewable within the view in a JavaScript dialog box with date ranges.

From the following code, the method ReadLogFile returns a correct SelectListItem. I call this method from my controller action method. My entity contains a property called RunDatesDisplay which is an IEnumerable List. I could have created this property as a select list item but I do not want to reference the System.Web.Mvc namespace in my domain project?

The problem is I am unable to cast the selectlist item to an IEnumerable list in my entity to pass to the view. I have created a listview model and within the view I will call the editor template to render the checkboxes.

I just need help to correctly pass the selectlist item to the view.
Should I pass the SelectListItem to the model property using ViewBag, for instance ViewBag.RunDatesDisplay = items(selectlistitem) or I should bind my selectlistitem to selectlist first?

Entity:

public class RunLogEntry
{

    public int ID { get; set; }

    public int RunID { get; set; }


    [NotMapped]
    public bool? LoadFileAttached { get; set; }

    [NotMapped]
    public bool? OutFileAttached { get; set; }

    [NotMapped]
    public string AttachedLoadListFileName { get; set; }

    [NotMapped]
    public string AttachedOutputFileName { get; set; }

    [NotMapped]
    public List<RunLogEntryTestExceptionDisplay> TestExceptionDisplay { get; set; }

    [NotMapped]
    public IEnumerable<RunLogEntryDatesDisplay> RunDatesDisplay { get; set; }
}

Method which does some processing and return a selectlistitem:

public static List<SelectListItem> ReadLogFile(List<string> fileNames)
{
    //Get collection of files and send to parser file by file:
    LogFile lf = new LogFile();


    var items = new List<SelectListItem>();
    foreach (var minDate in minDates)
    {
       var item = new SelectListItem() { Value = minDate.ToString(), Text = String.Format("{0} - {1}", minDate, minDate.AddMinutes(30)) };
        items.Add(item);
    }

    return items;
}

Controller Action(I did not include the entire code for the action)

//3. Send log file name collection to parser
if (logFiles != null && logFiles.Count > 0)
{
    var items = new List<SelectListItem>();

    items = FileImport.ReadLogFile(logFiles);
    **RunLogEntry.RunDatesDisplay = FileImport.ReadLogFile(logFiles);**

ViewModel:

public class RunLogRunDatesViewModel
{
    public IEnumerable<SelectListItem> RunLogRunDates { get; set; }
}

Editor Template

@model RunLog.Domain.Entities.RunDatesDisplay 

<tr>
    <td>
        @Html.DisplayFor(x => x.RunDate)
    </td>
</tr>

And finally my view:

<div id="runDatestreeview" title="Dialog Title" style="font-size: 10px; font-weight: normal;
            overflow: scroll; width: 800px; height: 450px; display: none;">
    <table class="grid" style="width: 600px; margin: 3px 3px 3px 3px;">
        <thead>
            <tr>
                <th>
                    Run Dates:
                </th>
            </tr>
        </thead>
        <tbody>
            @if (Model.RunDatesDisplay != null)
            {
                @Html.EditorFor(x => x.RunDatesDisplay)
            }
        </tbody>
    </table>
</div>
  • 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-15T19:30:47+00:00Added an answer on June 15, 2026 at 7:30 pm

    You can create custom type with two properties, or just use Tuple class, so your
    ReadLogFile could be something like this

    public static List<Tuple<string,string>> ReadLogFile(List<string> fileNames)
    {
       ...
       var items = new List<Tuple<string,string>>();
       foreach (var minDate in minDates)
       {
          var item = new Tuple<string, string>(minDate.ToString(), String.Format("{0} - {1}", minDate, minDate.AddMinutes(30));
          items.Add(item);
       }
    
       return items;
    }
    

    Your model:

    public class RunLogRunDatesViewModel
    {
           public SelectList RunLogRunDates { get; set; }
    }
    

    And your controller:

    var model = new RunLogRunDatesViewModel();
    List<Tuple<string,string>> items = FileImport.ReadLogFile(logFiles);
    model.RunLogRunDates = new SelectList(items, "Item1", "Item2");
    

    SelectList will try to get Value from “Item1” and Text from “Item2”

    Or, as I said at start you can create simple class with two properties to avoid using of Tuple

    UPDATE1
    In .Net 2.0-3.5, you can create simple wrapper for it:

    public class Tuple<T1,T2>
    {
        public T1 Item1 {get;set;}
        public T2 Item2 {get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to pass a string argument to a function, which will then be used
im trying to pass back from a user control a list of strings that
I'm trying to pass a list to a function in Lisp, and change the
Trying to pass some values into an imagebutton click event, something like this: <asp:ImageButton
Am trying to pass the selected check box value to the control function. Please
I'm trying pass in a url as a paramter to my controller like this:
I am trying pass a new variable into a template within django-registration. Here is
Im trying to pass a value of a date control from form1 to form2.
I am trying to pass a collection from my controller to view like so:
Trying to pass a date to an add item with the Lists web service

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.