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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:04:13+00:00 2026-05-31T01:04:13+00:00

I’ll explain my point: The best practice is to create views strongly typed with

  • 0

I’ll explain my point:
The best practice is to create views strongly typed with a Model. You only can stronly type one Model.

If you need two models in a view you can created two views and use Partial Render, but it seems not to be the very best option.

Another approach is to create another type model that encapsulates the other pieces of the model what you need; this make much more sense for me.

Then, my question is, in a complex proyect when a page needs to communicate with all the models and they are not direct realted, developers create a type that encapsulates all the other things?

  • 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-31T01:04:15+00:00Added an answer on May 31, 2026 at 1:04 am

    For non-related parts of your view, you may use Html.Action() to invoke an action that returns a partial view.
    This way, the logic of the “area” will be encapsulated in its own action and/or controller.

    Update: I don’t know if it’s really the best practice, but I prefer composition over complex views & view models. Even for related information, I prefer to break it to smaller partial views and child actions. As I see it, it has the following flexibility:

    1. Ability to easily move some of the partial views/child actions to a layout page
    2. Load the partial view asynchronously via AJAX query
    3. Reduced controller action complexity and increased maintainability.
    4. Better support for conditioned rendering
    5. Separation of concerns

    In (4) I mean that you can easily do the following without complicating your view model:

    <div class="header">
        @if (loggedInUser.ShowAds) {
            @Html.Action("Header", "Ads")
        }  
    </div>
    

    Answering the question in your comment.
    Considering twitter. There’s the content pane and the users box on the left.
    So here’s our TweetsController:

    public class TweetsController: Controller {
        public ActionResult Index() {
            var tweets = ...;
            return View(tweets);
        }
    }
    

    The Tweets/Index view may look like:

    @model Tweet[]
    <div class="leftPane">
        @Html.Action("Index", "Users");
    </div>
    <div class="mainContent">
        @foreach var t in Model {
            @t.User - @t.Text
        }
    </div>
    

    Note that the left pane just calls the Index action in UsersController to display the users list.
    Here’s how it may look like:

     public class UsersController: Controller {
         public ActionResult Index() {
             var users = ...;
             return PartialView(users);
         }
     }
    

    And here’s the partial view (Users/Index):

     @model User[]
     @foreach var u in Model {
         <img src="@u.IconUrl"/> @u.Name
     }
    

    So what will actually happen, when the Tweets view will be rendered Html.Action will put the partial view returned by UsersController.Index in the left pane.
    Of course you may move this logic into a layout if this behavior is common for a number of pages.

    Hope that helps.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker

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.