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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:10:59+00:00 2026-05-30T17:10:59+00:00

Extension to: How do you handle multiple submit buttons in ASP.NET MVC Framework? Let

  • 0

Extension to: How do you handle multiple submit buttons in ASP.NET MVC Framework?

Let us say a view is composed of partial views bound with related models, let’s say a student is required to provide multiple contact persons(partial view bound to Person model) and multiple contact numbers(partial view bound to a model) to get registered, sorry for the bad example. Once a contact person or number is added, an action (child postback or whatever) is called which validates the related model (not student model), adds it in a list and returns to the same page for further processing. Once all are added, the parent/master action validates whole student model and processes it.

How to validate the specific model for which an action is being called, add it to the page and return the same student view with added values in response?

  • 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-30T17:11:00+00:00Added an answer on May 30, 2026 at 5:11 pm

    This solution uses #2 (Session) since its simpler to code however this demonstrates the principles.

    Views

    Index View:

    @using StackOverflow.Models
    
        <div>
    
        @{ Html.RenderPartial("PersonGrid", Model.Persons, new ViewDataDictionary()); }
        @Html.Partial("NewPerson", new Person())
        @{ Html.RenderPartial("ContactGrid", Model.Contacts, new ViewDataDictionary()); }
        @Html.Partial("NewContact", new Contact())
    
        @using(Html.BeginForm("Validate", "Home", FormMethod.Post))
        {
            <input type="submit" value="Validate" />
        }
        </div>
    
    

    Person Grid

    
        @model IList
    
        <table>
            <thead>
                <tr>
                    <td>First Name</td>
                    <td>Last Name</td>
                </tr>
            </thead>
    
            <tbody>
                @if (Model != null && Model.Any())
                {
                    foreach (var person in Model)
                    {
                        <tr>
                            <td>@person.FirstName</td>
                            <td>@person.LastName</td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td colspan="2" style="text-align: center">No persons available</td>
                    </tr>
                }
            </tbody>
        </table>
    
    

    Contact Grid

    
        @model IList
    
        <table>
            <thead>
                <tr>
                    <td>Phone</td>
                </tr>
            </thead>
            <tbody>
                @if (Model != null && Model.Any())
                {
                    foreach (var contact in Model)
                    {
                        <tr>
                            <td>@contact.Phone</td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td>No contacts available</td>
                    </tr>
                }
            </tbody>
        </table>
    
    

    New Person

    
        @model StackOverflow.Models.Person
    
    
        @using (Html.BeginForm("NewPerson", "Home", FormMethod.Post))
        {
            <div>
                @Html.Hidden("PersonViewState", TempData["PersonViewState"])
    
                @Html.LabelFor(m => m.FirstName)<br />
                @Html.TextBoxFor(m => m.FirstName)<br />
    
                <br />
    
                @Html.LabelFor(m => m.LastName)<br />
                @Html.TextBoxFor(m => m.LastName)<br />
    
                <br />
                <input type="submit" value="Submit" />
            </div>
        }
    
    

    New Contact

    
        @model StackOverflow.Models.Contact
    
        @using (Html.BeginForm("NewContact", "Home", FormMethod.Post))
        {
            <div>
                @Html.LabelFor(m => m.Phone)<br />
                @Html.TextBoxFor(m => m.Phone)<br />
                <br />
                <input type="submit" value="Submit" />
            </div>
        }
    
    

    Models

    
    
        public class Person
        {
            [Display(Name = "First Name")]
            public string FirstName { get; set; }
    
            [Display(Name = "Last Name")]
            public string LastName { get; set; }
        }
    
        public class Contact
        {
            [Display(Name = "Phone")]
            public string Phone { get; set; }
        }
    
        public class HomeModel
        {
            public IList<Person> Persons { get; set; }
            public IList<Contact> Contacts { get; set; }
        }
    
    

    Helpers

    
    
        public static class PersistenceMechanism
        {
            public static IList GetPersons()
            {
                return (IList<Person>) HttpContext.Current.Session["__Persons"];
            }
    
            public static IList GetContacts()
            {
                return (IList<Contact>) HttpContext.Current.Session["__Contacts"];
            }
    
            public static void Update(IList<Person> persons)
            {
                HttpContext.Current.Session["__Persons"] = persons;
            }
    
            public static void Update(IList<Contact> contacts)
            {
                HttpContext.Current.Session["__Contacts"] = contacts;
            }
        }
    
    

    Controller

    
    
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                var model = new HomeModel
                                {
                                    Persons = PersistenceMechanism.GetPersons(),
                                    Contacts = PersistenceMechanism.GetContacts()
                                };
                return View(model);
            }
    
            [HttpGet]
            public ActionResult PersonGrid()
            {
                var persons = PersistenceMechanism.GetPersons();
    
                return PartialView(persons);
            }
    
            [HttpGet]
            public ActionResult ContactGrid()
            {
                var contacts = PersistenceMechanism.GetContacts();
    
                return PartialView(contacts);
            }
    
            [HttpPost]
            public ActionResult NewPerson(Person model)
            {
                var persons = PersistenceMechanism.GetPersons() ?? new List<Person>();
                persons.Add(model);
                PersistenceMechanism.Update(persons);
    
                return RedirectToAction("Index");
            }
    
            [HttpPost]
            public ActionResult NewContact(Contact model)
            {
                var contacts = PersistenceMechanism.GetContacts() ?? new List<Contact>();
                contacts.Add(model);
                PersistenceMechanism.Update(contacts);
                return RedirectToAction("Index");
            }
    
            [HttpPost]
            public ActionResult Validate()
            {
                var persons = PersistenceMechanism.GetPersons();
                var contacts = PersistenceMechanism.GetContacts();
    
                // validate
                // ...
    
                return RedirectToAction("Index");
            }
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a Servlet to handle requests to files depending on prefix and extension,
I need to create a WiX extension to handle interacting with the HTTP API
I'm using the SlowCheetah XML Transforms extension to handle web.config-like transformations with app.config. That
I'm trying to put the following logic into an Extension method that let's me
I'm trying to find a unit test framework, for the .NET platform, that can
Hi I have converted this parallel extension c# code sample to VB.NET http://code.msdn.microsoft.com/Samples-for-Parallel-b4b76364/sourcecode?fileId=25353&pathId=215900242 using
I need to add an ability to a Firefox extension to handle cases when
Here's the background info first. ASP.NET 2.0 Web Site with AJAX Extensions 1.0. I
I created a script in HTML5 to handle multiple files uploads using XHR's progress
I am writing an extension for an existing application that needs to handle USB

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.