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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:38:12+00:00 2026-06-01T20:38:12+00:00

I want to pass an input model from a partial view to a controller.

  • 0

I want to pass an input model from a partial view to a controller. I’m rather new to MVC so still trying to understand how the default model binder works.

Via AJAX (listBox) a controller passes back a partial view and inserts into table id=searchResults.

@model ViewModels.LocationViewModel
@using (Ajax.BeginForm("ProcessSearch", "SearchR", new AjaxOptions
{
    HttpMethod = "GET",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "searchResults",
}))

{ 
    <div>@Html.ListBoxFor(xxx)</div>
    <input id="Search" type="submit" value="Search" />
}

Here is the controller and ViewModel that populates the partial view

public class OrderViewModel
{
    public string Description       { get; set; }
    public string Status            { get; set; }     
}

public ActionResult ProcessSearch(SearchViewModel search)
{
     select new OrderViewModel{
                Status=f.STATUS,
                Description=f.DESCRIPTION}).ToList();
     return PartialView(model);
}

In the same main view I have this form that I want I want to bind to yet another view model. I simply don’t understand how to implement the default binder from the model of the partial view. I apologize if I didn’t explain this correctly. I hope it makes sense.

@using (Html.BeginForm("Testing", "SearchR", FormMethod.Post))
{ 
    <div>@Html.DropDownListFor(yyy)</div>
    <input id="Reshop" type="submit" value="Reshop" />
}
<table id="searchResults"></table>


public ActionResult Testing(RSOrderViewModel rOrder)
{
    return Content("hey");
}

public class RSOrderViewModel 
{
    public string yyy { get; set; }
    public IEnumerable<OrderViewModel> sovm { get; set; }
}


@model List<ViewModels.OrderViewModel>

@{ViewData.TemplateInfo.HtmlFieldPrefix = "sovm";
   }

 <table id="searchResults">
    <tr>
        <th>Order Id</th>
        <th>Order Detail</tr>

@for (int i = 0; i < Model.Count; i++)
{
    <tr>
        <td>
         @Html.DisplayFor(x => x[i].OrderId)
        </td>
        <td>
         @Html.DisplayFor(x => x[i].OrderDetail)
        </td>
    </tr>
}

</table>
  • 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-01T20:38:15+00:00Added an answer on June 1, 2026 at 8:38 pm

    The table is outside the second form. So when you POST to the Testing action all that is sent to the controller is the value of the dropdown list. If you want to send the collection that’s stored in this table you will have to either use AJAX or put the table inside the form:

    @using (Html.BeginForm("Testing", "SearchR", FormMethod.Post))
    { 
        <div>@Html.DropDownListFor(yyy)</div>
        <table id="searchResults"></table>
        <input id="Reshop" type="submit" value="Reshop" />
    }
    

    Now of course putting the table inside the form doesn’t mean that it will send anything to the server when you submit the form. You need to put input fields (hidden if you don’t want them to be visible to the user) that will contain the values that will be POSTed back. Also those input field names must follow the standard convention for binding to a list.

    You haven’t actually shown how does the partial view look like but here’s an example of how it might look so that the convention is respected. For example let’s suppose that you have 2 properties in your OrderViewModel that you want to be bound: OrderId and OrderDetail:

    @model IEnumerable<OrderViewModel>
    @{
        // We set the name prefix for input fields to "sovm"
        // because inside your RSOrderViewModel the collection 
        // property you want to bind to this table is called sovm
        // and in order to respect the convention the input names
        // must be in the following form "sovm[0].OrderId", "sovm[1].OrderId", ...
        ViewData.TemplateInfo.HtmlFieldPrefix = "sovm";
    }
    <thead>
        <tr>
            <th>Order Id</th>
            <th>Order detail</th>
        </tr>
    </thead>
    <tbody>
        @Html.EditorForModel()
    </tbody>
    

    and then you could have an editor template which will be rendered for each element of the model (~/Views/Shared/EditorTemplates/OrderViewModel.cshtml):

    @model OrderViewModel
    <tr>
        <td>@Html.EditorFor(x => x.OrderId)</td>
        <td>@Html.EditorFor(x => x.OrderDetail)</td>
    </tr>
    

    The name of the template is the name of the type used in the collection you want to bind to (IEnumerable<OrderViewModel> sovm { get; set; } => OrderViewModel.cshtml). It must also be placed inside the ~/Views/Shared/EditorTemplates folder if it can be reused between multiple controllers or if it is specific to the current controller inside the ~/Views/XXX/EditorTemplates folder where XXX is the current controller.

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

Sidebar

Related Questions

I want to pass two values from view to controller . i.e., @Model.idText and
i want to pass a string from an input box that after submition automatically
I would like to pass parameter from view to controller in cshtml page. This
I want to pass the id of the INPUT field to the PHP file
Please keep in mind that I'm rather new to how MVC, Json, jQuery, etc.
How can i add pass Model-Specific urls to the Template. Let's say, i want
When I pass a model to my View in a form, the fields are
I want pass a class-instace to a method of an other and be sure
I want to pass a few variables to another page. Currently I'm using response.redirect
i want to pass large variables to a PHP script on another server with

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.