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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:05+00:00 2026-05-31T18:09:05+00:00

I am trying to make a view that edits a list of predefined models.

  • 0

I am trying to make a view that edits a list of predefined models.
Therefore it is a strongly typed view that takes as parameter a list of models .
I use custom Html helpers to edit the individual models.
The Get view is displayed properly but the post back view model (the list of models) is always null.
I know there are many questions on here about this topic but I ve been trying to do this for 2 days now.

Here is the base Model:

public class PrivacyManagerModel
{
   [Required]
   [Display(Name="Privacy Type Id")]
   public int PrivaceTypeId { get; set; }

   [Required]
   [Display(Name = "Visibility Level Id")]
   public int VisibilityLevelId { get; set; }



}

Here are the Controller Actions:

     //GET: /Profile/ManagePrivacy
    [Authorize]
    public ActionResult ManagePrivacy()
    {
        PrivacyTypeService _privacyTypeService=new PrivacyTypeService();
        IEnumerable<PrivacyFlagType> privacyTypes = _privacyTypeService.GetPrivacyFlagTypes();
        List<PrivacyManagerModel> model=new List<PrivacyManagerModel>();
        foreach (PrivacyFlagType type in privacyTypes)
        {
            PrivacyManagerModel temp=new PrivacyManagerModel();
            temp.PrivaceTypeId=type.PrivacyFlagTypeId;
            model.Add(temp);
        }


        ViewBag.privacyTypes=privacyTypes;



        return View(model);
    }

    //POST: /Profile/ManagePrivacy
    [Authorize]
    [HttpPost]
    public ActionResult ManagePrivacy(IEnumerable<PrivacyManagerModel> model)
    {

        if (ModelState.IsValid)
        {
        do stuff
        }
        else
        {
            return View(model);
        }
    }

This is the view that tries to edit the List of PrivacyManagerModel:

@model IEnumerable<Klever.PrivacyManagerModel>
@using Klever
@{
 ViewBag.Title = "ManagePrivacy";
 var _privacyTypes = ViewBag.privacyTypes as IEnumerable<PrivacyFlagType>;
}

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>

    @foreach(PrivacyManagerModel item in Model)
    {
        <div class="display-label">
        @Html.DisplayFor(modelItem=>item.PrivaceTypeId)
        </div> 
        <div class="editor-field">
        @Html.EditorFor(modelItem=>item)
        </div>
        }

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}

<div>
 @Html.ActionLink("Back to List", "Index")
</div>

and finally the Html helper EditTemplate for PrivacyManagerModel:

@model Klever.PrivacyManagerModel
@using Klever.Components
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"    type="text/javascript"></script>

@{
PrivacyTypeService _privacyService = new PrivacyTypeService();
var visibilityLevels=_privacyService.GetVisibilityLevels();

}
<fieldset>


    <div class="editor-label">
        @Html.LabelFor(model => model.PrivaceTypeId)
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model=>model.VisibilityLevelId,new SelectList(visibilityLevels,"VisibilityLevelId","Name"))
        @Html.ValidationMessageFor(model => model.VisibilityLevelId)
    </div>
    </fieldset>

Again, the GET action works fine ( It shows the view properly) but the Post action always receives a Null model as parameter.
I would greatly appreciate your help.
Thanks

  • 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-05-31T18:09:06+00:00Added an answer on May 31, 2026 at 6:09 pm

    You can try this. I had similar problem when I was working on MVC 3 site in a project. The reason being that MVC platform is not able to generate the model back from the values in the View, because when we apply foreach loop and create control for any item in the loop as “@Html.DisplayFor(modelItem=>item.PrivaceTypeId)” the id/name assigned to the HTML control will be “item.PrivaceTypeId”. But in the example given below the id/name assigned to HTML control would be “Model[0].PrivaceTypeId”, “Model[1].PrivaceTypeId”, and so on… and this would help to create Model (collection) from the values in the view.

    @using (Html.BeginForm()) { 
    @Html.ValidationSummary(true) 
    <fieldset> 
    
        @for(int i = 0; i <= Model.Count; i++)
        { 
            <div class="display-label"> 
            @Html.DisplayFor(modelItem=>Model[i].PrivaceTypeId) 
            </div>  
            <div class="editor-field"> 
            @Html.EditorFor(modelItem=>Model[i]) 
            </div> 
        } 
    
        <p> 
            <input type="submit" value="Create" /> 
        </p> 
    </fieldset> 
    } 
    

    I am not sure if the MVC platform will be able to create the model from editor template because I don’t have VS now. You can check and see. But this will surely work as it has worked for me 4-5 times.

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

Sidebar

Related Questions

I am trying to make a view that contains several tableViews in it -
I am trying to make a application that uses the standard Split View Application
I'm trying to make a custom view in Django admin. I'm reading from this
I'm trying to make a Horizontal List View with two arrows, one to move
I am trying to make a view that allows a user to edit a
I am trying to design a view that takes in from and to locations
I have two tables in the system. I'm trying to make a VIEW that
I'm trying to create a custom cursoradapter that will use two different layouts depending
I am trying to make a view which selects all unread mails which also
I am trying to make a search view in Django. It is a search

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.