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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:18+00:00 2026-05-24T16:15:18+00:00

I’m trying to make a partial view that acts as the following: When user

  • 0

I’m trying to make a partial view that acts as the following:

  • When user is not logged on, show a registration form.

  • When user is logged on, show me that users information.

I have a partial view that acts as both as registration form, and a user information card; depending on whether or not the user is logged in.

Since this partial view has to be visible from anywhere in the website, I wrote it in the _layout area of the MVC3 application:

<body>
    <div id="wrapper">

        <div id="top">
            <p id="onlinecount">7890 Personas Jugando</p>
            <p id="logoncontrol">ENTRAR | REGISTRARSE</p>
        </div>

        <div id="headercontainer">
            <img src="../../Content/Images/topheadertemp.png" />
        </div>

        <div id="middle">
            <div id="playerinformation">
                @Html.Partial("_RegisterPartial") <!-- HERE! -->
            </div>            

            <div id="centerad">
                <img src="../../Content/Images/premio.png" />
            </div>

            <div id="rightad">
                <img src="../../Content/Images/ganadores.png" />
            </div>

            <div class="clear"></div>
        </div>

        <div id="bottom">@RenderBody()
        </div>

    </div>
</body>

Basically, I need to show a form in that partial if the user is not logged on. However if he IS logged on (via cookie or whatever), I should load a model of his information in order to display the data for his account.

Here’s where I’m stuck. I don’t know how to load the model for this usage. Since this is in the _layout, no controller acts on it if I’m correct, no?

Any suggestions?

  • 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-24T16:15:19+00:00Added an answer on May 24, 2026 at 4:15 pm

    You should look at this previous question, which is similar to yours.

    You should have registration and user information in a single model for your page. (So the answer to your question is that your page only has one model. But your model can be made up of other objects — one for each partial view.)

    So as you see in the link, the user had partial views only use those objects in the page model that pertained to it.

    I think this should help you out. Hope this helps! Good luck.

    UPDATE: Sorry for the delay, but here’s an example (lots of code) that may help:

    Model:
    I create an abstract view model that always has reg and user data in it. Every page’s model could inherit from this abstract.

    public class Registration
    {
        public string UserName { get; set; }
        public string Password { get; set; }
    }
    
    public class UserData
    {
        public string DisplayName { get; set; }
        public int Age { get; set; }
    }
    
    public abstract class RegModelViewModelBase
    {
        public string Title { get; set; }
        public Registration RegInfo { get; set; }
        public UserData UserInfo { get; set; }
    }
    
    public class MainPageViewModel : RegModelViewModelBase
    {
    }
    

    Controller:
    Here, I just instantiate the concrete view model for this page/view (MainPageViewModel). I set properties (which could come from the database, etc.). I pass the view model to the view.

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            MainPageViewModel hpvm = new MainPageViewModel();
    
            hpvm.Title = "Some Cool Page";
            hpvm.RegInfo = new Registration() { Password = "blah", UserName = "dhoerster" };
            hpvm.UserInfo = new UserData() { DisplayName = "David Hoerster", Age = 125 };
    
            return View(hpvm);
        }
    }
    

    View — _Layout.cshtml:
    Notice that the first line in my model sets the model object for my _layout template. I’m getting this view model from the controller, and I can reference it in _layout (or other template). I don’t do much here, except get a partial view (_RegStuff) and pass to it my RegInfo from my model (which was set in the controller):

    @model MvcApplication1.Models.RegModelViewModelBase
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>@Model.Title</title>
    </head>
    
    <body>
        @Html.Partial("_RegStuff", Model.RegInfo)
        @RenderBody()
    </body>
    </html>
    

    View — _RegInfo.cshtml:
    Dirt simple, but again I set my model type that this partial view expects to be passed in.

    @model MvcApplication1.Models.Registration
    <div>User Name = @Model.UserName</div>
    

    View — Index.cshtml:
    Again, set the model and use it in my index view.

    @model MvcApplication1.Models.MainPageViewModel
    
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <h2>@Model.Title</h2>
    <h3>Display Name = @Model.UserInfo.DisplayName</h3>
    

    So throughout, I can reference the model set in my controller.

    I hope this explains what I was trying to get at. If not, I can update this accordingly.

    Thanks!

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

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests
I'm parsing an XML file, the creators of it stuck in a bunch social
I am using Paperclip to handle profile photo uploads in my app. They upload

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.