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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:39:32+00:00 2026-05-23T16:39:32+00:00

How do I pass variables to multiple partial views within a view? My idea

  • 0

How do I pass variables to multiple partial views within a view? My idea is that every partial view will make up a different field in a form, and I plan on using dynamically created DOM objects with each partial view. So I need to pass in 3 parameters. An ID (to uniquely identify each DOM object), and its particular controller and action. How would I go about doing this in a view?

For example, I want to do something along the lines of…

@Html.Partial("_BookField", Model, 1, "book", "updateauthor")

@Html.Partial("_BookField", Model, 2, "book", "updatetitle")

@Html.Partial("_BookField", Model, 3, "book", "updatepublisher")

Is there a way to do this without adding additional attributes in the model?

Edit: After conferring with one of my coworkers, he also brought up a point that I’d like clarification on. He suggested that what I’m doing, which is introducing controller/action logic in the view is breaking the MVC concept. But things like ActionLinks, you have to put in the controller and action in an actionlink for it to be able to do something. Is what I’m trying to do considered breaking the MVC paradigm?

  • 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-23T16:39:32+00:00Added an answer on May 23, 2026 at 4:39 pm

    You use view models of course:

    public class SubViewModel
    {
        public int Id { get; set; }
        public string Book { get; set; }
        public string Author { get; set; }
    }
    

    and then have your main view model different properties of this SubViewModel:

    public class MyMainViewModel
    {
        public SubViewModel Sub1 { get; set; }
        public SubViewModel Sub2 { get; set; }
        public SubViewModel Sub3 { get; set; }
    }
    

    and then simply:

    @Html.Partial("_BookField", Model.Sub1)
    @Html.Partial("_BookField", Model.Sub2)
    @Html.Partial("_BookField", Model.Sub3)
    

    Of course it is the now the controller action responsibility to fill those view models (as always). And if you use editor/display templates your code might be even simpler, just like this:

    @Html.DisplayFor(x => x.Sub1)
    @Html.DisplayFor(x => x.Sub2)
    @Html.DisplayFor(x => x.Sub3)
    

    and because this strangely looks to me like a collection, well, you could use a collection:

    public class MyMainViewModel
    {
        public SubViewModel[] Subs { get; set; }
    }
    

    and then simply:

    @Html.DisplayFor(x => x.Subs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass multiple variables in a URL in PHP to GET
Is it possible to pass variables between multiple calls to the around MethodModier ?
In a vxWorks Real-Time process, you can pass environment variables as one of the
I want to call an ASHX file and pass some query string variables from
We are trying to create a web-service that we plan to pass a variable
OK so I have a strongly-typed Customer Details view that takes a Customer object
I am trying to pass custom variables to paypal IPN. I can manage to
Scenario/Problem Isolation : Lets suppose my program uses MULTIPLE variables. At the program beginning
So I'm trying to learn how to pass arrays through a function, so that
I figured out how to pass one.. but how do I pass multiple GET

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.