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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:39:59+00:00 2026-06-06T21:39:59+00:00

I’m using ASP.NET MVC 4 for a website, and one of the things I’m

  • 0

I’m using ASP.NET MVC 4 for a website, and one of the things I’m making is a CSV import. I want to map the CSV columns onto properties of the ORM. After the file is uploaded, I want to display the column number, the first line (containing the header in the csv file) and the second line (data preview).

/// <summary>
/// The mapping view model.
/// </summary>
public class MappingViewModel
{
    #region Public Properties

    /// <summary>
    /// Gets or sets the mappings.
    /// </summary>
    public IList<Mapping> Mappings { get; set; }

    public MappingViewModel()
    {
        //this.Mappings = new List<Mapping>();
    }

    public string FileName { get; set; }

    #endregion
}

/// <summary>
/// The mapping.
/// </summary>
public class Mapping
{
    #region Public Properties

    public int ColumnIndex { get; set; }

    public string ColumnHeader { get; set; }

    public string DataPreview { get; set; }

    public string PropertyIdentifier { get; set; }

    #endregion
}

I’ve created a strongly typed Razor view where I loop through the list inside the model as follows:

@model MappingViewModel


@using (Html.BeginForm("ApplyMapping", "Person"))
{
    @Html.EditorFor(t=>t.FileName)
    <table class="i-table fullwidth">
        <thead>
...table header
        </thead>
        @foreach (var mapping in Model.Mappings)
        {
            <tr>
                <td>@Html.EditorFor(x=>mapping.ColumnIndex)</td>
                <td>@Html.EditorFor(x => mapping.ColumnHeader)</td>
                <td>@Html.EditorFor(x => mapping.DataPreview)</td>
                <td>@Html.DropDownListFor(x=>mapping.PropertyIdentifier,(SelectList)ViewBag.PropertyList)</td>
            </tr>
        }
    </table>
    <input type="submit" value="@Resources.Default.ButtonSaveText" class="icon16-button forms-16" />
}

And that’s not working for me. The data is displayed, but the receiving controller action gets an empty model – with the exception of the filename.

What am I doing wrong?

P.S. Action is as follows:

        [HttpPost]
        public ActionResult UploadAdvanced(FormCollection collection)
        {
 // csv stuff + get property list

            var viewModel = new MappingViewModel();
            viewModel.Mappings = new List<Mapping>();
            for (int i = 0; i < headers.Count(); i++)
            {
                viewModel.Mappings.Add(new Mapping() { ColumnIndex = i, DataPreview = firsLine[i], ColumnHeader = headers[i],PropertyIdentifier = string.Empty });
            }
            viewModel.FileName = file.FileName;
            var propertyList = new SelectList(propList);
            this.ViewBag.PropertyList = propertyList;
            return this.View("Mapping", viewModel);
        }


        [HttpPost]
        public ActionResult ApplyMapping(MappingViewModel model)
        {
            System.Diagnostics.Debug.WriteLine(model.ToString());

            return this.View("Index");
        }

I’m reading the viewmodel props from a breakpoint in the ApplyMapping actionResult. When the breakpoint hits – filename is set correctly, the list is NULL

  • 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-06T21:40:00+00:00Added an answer on June 6, 2026 at 9:40 pm

    It’s empty probably because all the properties are using a DisplayFor instead of EditorFor second they need to be inside of the BeginForm, if you Could you shows us the action?

    UPDATE

    Change the datatype from IList to IEnumerable, second initialize the attribute in the constructor.

    /// <summary>
    /// The mapping view model.
    /// </summary>
    public class MappingViewModel
    {
        #region Public Properties
    
        /// <summary>
        /// Gets or sets the mappings.
        /// </summary>
        public IEnumerable<Mapping> Mappings { get; set; }
    
        public MappingViewModel()
        {
            //this.Mappings = new List<Mapping>();
            IEnumerable<Mapping> test = new HashSet<Mapping>();
        }
    
        public string FileName { get; set; }
    
        #endregion
    }
    

    UPDATE 2

    Created a EditorTemplate in this path (/Views/Shared/EditorTemplates/) for your class Mapping with the format that you need for example

    @model SomePath.Models.Mapping 
    
    <tr> 
        <td>@Html.EditorFor(model => model.ColumnIndex)</td>
        <td>@Html.EditorFor(model => model.ColumnHeader)</td>
    </tr>
    

    Then Remove the for in the View for the property Mapping and usee the EditorFor Helper like this

    @Html.EditorFor(x=>x.Mappings) 
    

    That should the problem of serialize the attribute

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported

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.