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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:45:03+00:00 2026-05-25T14:45:03+00:00

When i try to post data and call a action from a view having

  • 0

When i try to post data and call a action from a view having partial view i do not get the Model data for the partial view but when i use it directly and not the partial view it sends the data properly.

<div id="mydiv">
    @using (Ajax.BeginForm("Index1", "Home", new AjaxOptions { UpdateTargetId = "mydiv", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" }))
    {        
        //Does not send data to action on post  
        @Html.Partial("ViewUserControl1",Model.Emps)
        //ViewUserControl1 contains the same next 8 line logic.
        OR

        //Send the data to actions on post.
        for (int i = 0; i < Model.Emps.Count(); i++)
        {
            @Html.TextBoxFor(x => x.Emps[i].Name)
            @Html.TextBoxFor(x => x.Emps[i].Address)
            @Html.ValidationMessageFor(x => x.Emps[i].BBString)
        <br />    
        }

        <input id="dosomething" type="submit" value="save" />
    }
</div>


///On Controller 
   [HttpPost]
   public ActionResult Index1(MyModel model)
   {
      ///Here i am looking for the model data which is null for partial.
      return View(model);
   }

Where MyModel has a List of Emps { Name,Address}

Does anybody know the reason for this.

  • 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-25T14:45:04+00:00Added an answer on May 25, 2026 at 2:45 pm

    I suspect that your ViewUserControl1 partial looks like this (you haven’t shown it, you just said that it looks like the following 8 lines but it obviously it doesn’t look those 8 lines because it uses a different view model):

    @model IEnumerable<Employee>
    
    for (int i = 0; i < Model.Count(); i++)
    {
        @Html.TextBoxFor(x => x[i].Name)
        @Html.TextBoxFor(x => x[i].Address)
        @Html.ValidationMessageFor(x => x[i].BBString)
        <br />    
    }
    

    Notice the missing Emps property in the lambdas? This generates invalid names for the input fields and the default model binder does not fetch the values when you post back.

    I would recommend you using editor templates instead of partial views, like this:

    <div id="mydiv">
        @using (Ajax.BeginForm("Index1", "Home", new AjaxOptions { UpdateTargetId = "mydiv", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" }))
        {        
            @Html.EditorFor(x => x.Emps)
            <input id="dosomething" type="submit" value="save" />
        }
    </div>
    

    and then inside ~/Views/SomeControllerName/EditorTemplates/Employee.cshtml simply:

    @model Employee
    @Html.TextBoxFor(x => x.Name)
    @Html.TextBoxFor(x => x.Address)
    @Html.ValidationMessageFor(x => x.BBString)
    <br/>
    

    The editor template will be rendered for each element of the Emps collection so that you do not need to write any loops. It will generate proper names for the input fields so that the default model binder is able to populate the values on postback. The editor template location is important. It must be placed either inside ~/Views/Shared/EditorTemplates (if you want it to be reused between multiple controllers) or inside ~/Views/SomeControllerName/EditorTemplates (if you want it to be reused only between the views of a given controller). The name of the template is also important. It should be called the same as the type of the collection. So for example if you have a property public IEnumerable<Employee> Emps { get; set; } in your view model, the template must be called Employee.cshtml so that it is automatically rendered for each element of this collection.

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

Sidebar

Related Questions

I try to use XMLHttpRequest() to post data to a url. I wrote the
I have a POST controller action like: if (ModelState.IsValid) { try { //.. save
Recently, I made a post about the developers I'm working with not using try
I am making a page that accepts post data from any number of pages
I have try to post value from page a to page b via jquery
I'm having problems trying to call a Javascript function from an enqueued javascript file
I am trying to debug the reason why my ajax get/post is not working
I'm using WSGI and trying to access the get/post data, using this code: import
I'm trying to call an Oracle Stored Procedure which returns XMLType data, but all
HttpRequestValidationException occurs when I try post when txtBulletin contains any HTML, like Hello<br />World

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.