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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:41:58+00:00 2026-06-01T16:41:58+00:00

I am working on a web app using MVC, where all pages have header

  • 0

I am working on a web app using MVC, where all pages have header section consiting of three dropdowns one text box and an image button. So no matter on which page user is, he/she has ability to select a combination out of three dropdowns, enter some text in text box and hit image button to search in database.

So i am using a strongly typed(BaseViewModel) master _Layoutthought, and then add two partial views on it, one to display user info and another one to display all dropdowns, text box and imaage button. Now, Models i have 3 models for each dropdown option/item and then a BaseViewModel which will have 3 properties as a list of each model and 3 int properties to hold selected item ID. And plan is to use this baseViewModel as parent class for all viewmodels so that i can fullfil my strongly tyed _Layout for each request and responce. OK i am not sure that if i have explained my requirement clearly :(.

so here is the code
all models:

    namespace XYZNameSpace.Models
{
    public class ManageCompany
    {
        public long ManageCompanyID { get; set; }

        public string ManageCompanyName { get; set; }
    }
}

    namespace XYZNameSpace.Models
{
    public class SuperCompany
    {
        public long SuperCompanyID { get; set; }

        public string SuperCompanyName { get; set; }
    }
}

    public class User
{
    public long UserID { get; set; }

    public string UserName { get; set; }

    public string UserLoginName { get; set; }

    public string UserLevel { get; set; }

    public int UserLevelId { get; set; }
}

    namespace XYZNameSpace.Models
{
    public class SearchResult
    {
        public string CompanyName { get; set; }

        public string SubCompanyName { get; set; }

        public string UserName { get; set; }
    }
}

ViewModel

    namespace XYZNameSpace.ViewModels
{
    public class BaseViewModel : User
    {
        public long SelectedManageCompanyID { get; set; }

        public List<SelectListItem> ManageCompanyList { get; set; }

        public string SelectedManageCompanyName { get; set; }

        public long SelectedSuperCompanyID { get; set; }

        public List<SelectListItem> SuperCompanyList { get; set; }

        public string SelectedSuperCompnayName { get; set; }

        public int SelectedSearchOptionID { get; set; }

        public List<SelectListItem> SearchOptionsList { get; set; }

        public string SelectedSearchOptionName { get; set; }

        public string SearchWord { get; set; }
    }

    public class SearchOption
    {
        public int SearchOptionID { get; set; }

        public string SearchOptionName { get; set; }
    }
}

    namespace XYZNameSpace.ViewModels
{
    public class SearchResultsViewModel : BaseViewModel
    {
        public List<SearchResult> ResultsList { get; set; }
    }
}

Controller

public class HomeController : Controller
{
    //
    // GET: /Home/

    public ActionResult Home()
    {
        BaseViewModel bVM = new BaseViewModel()
        {
            ManageCompanyList = (new List<ManageCompany>() {
                new ManageCompany()
                {
                    ManageCompanyID = 1,
                    ManageCompanyName = "MC 1"
                },
                                    new ManageCompany()
                {
                    ManageCompanyID = 2,
                    ManageCompanyName = "MC 2"
                },
                                    new ManageCompany()
                {
                    ManageCompanyID = 3,
                    ManageCompanyName = "MC 3"
                },
                                    new ManageCompany()
                {
                    ManageCompanyID = 4,
                    ManageCompanyName = "MC 4"
                },
                                    new ManageCompany()
                {
                    ManageCompanyID = 5,
                    ManageCompanyName = "MC 5"
                }
             }).Select(x => new SelectListItem { Value = x.ManageCompanyID.ToString(), Text = x.ManageCompanyName }).ToList(),
            SuperCompanyList = (new List<SuperCompany>(){
             new SuperCompany(){
                SuperCompanyID=6,
                SuperCompanyName="SC 6"
             },
             new SuperCompany(){
                SuperCompanyID=7,
                SuperCompanyName="SC 7"
             },
             new SuperCompany(){
                SuperCompanyID=8,
                SuperCompanyName="SC 8"
             },
             new SuperCompany(){
                SuperCompanyID=9,
                SuperCompanyName="SC 9"
             },
             new SuperCompany(){
                SuperCompanyID=10,
                SuperCompanyName="SC 10"
             }
             }).Select(y => new SelectListItem { Value = y.SuperCompanyID.ToString(), Text = y.SuperCompanyName }).ToList(),

            SearchOptionsList = (new List<SearchOption>(){
             new SearchOption(){
                SearchOptionID=11,
                SearchOptionName="SO 11"
             },
             new SearchOption(){
                SearchOptionID=12,
                SearchOptionName="SO 12"
             },
             new SearchOption(){
                SearchOptionID=13,
                SearchOptionName="SO 13"
             },
             new SearchOption(){
                SearchOptionID=14,
                SearchOptionName="SO 14"
             },
             new SearchOption(){
                SearchOptionID=15,
                SearchOptionName="SO 15"
             }
             }).Select(y => new SelectListItem { Value = y.SearchOptionID.ToString(), Text = y.SearchOptionName }).ToList()
        };

        return View(bVM);
    }

    [HttpPost]
    public ActionResult Search(BaseViewModel bVM)
    {
        SearchResultsViewModel sRVM = new SearchResultsViewModel();
        sRVM.ResultsList = new List<SearchResult>(){
            new SearchResult()
            {
             CompanyName = bVM.SelectedSuperCompanyID.ToString(),
             SubCompanyName = bVM.SelectedManageCompanyID.ToString(),
             UserName = "Duh"
            }
        };
        return View("SearchResults", sRVM);
    }
}

Views /Home/Home.cshtml

@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div style="float: left; vertical-align: top;">

</div>
<br />

/Home/SearchResults.cshtml

@model XYZNameSpace.ViewModels.SearchResultsViewModel
<table width="100%">
    <thead>
        <tr>
            <td>
                COMPANY
            </td>
            <td>
                SUB COMPANY
            </td>
            <td>
                USER NAME
            </td>
        </tr>
    </thead>
    <tbody>
        @foreach (XYZNameSpace.Models.SearchResult sr in Model.ResultsList)
        {
            <tr>
                <td>
                    @sr.CompanyName
                </td>
                <td>
                    @sr.SubCompanyName
                </td>
                <td>
                    @sr.UserName
                </td>
            </tr>
        }
    </tbody>
</table>

/Shared/SearchDDLPartialView.cshtml

    @model XYZNameSpace.ViewModels.BaseViewModel
<div>
    <div style="float: left">
        <span class="Label">Search: </span>
        @using (Html.BeginForm("Search", "Home", FormMethod.Post))
        {
            @Html.DropDownListFor(x => x.SelectedSuperCompanyID, Model.SuperCompanyList)
            @Html.DropDownListFor(x => x.SelectedManageCompanyID, Model.ManageCompanyList)
            @Html.DropDownListFor(x => x.SelectedSearchOptionID, Model.SearchOptionsList)
            <input type="image" src="../../Content/images/search.gif" />

        }
    </div>
</div>

/Shared/_Layout.cshtml

@model XYZNameSpace.ViewModels.BaseViewModel
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/BEClientProfile.css")" rel="Stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>
<body>
    <table>
        <tr>
            <td>
                <img src="../../Content/images/logo124.gif" alt="Logo" />
            </td>
            <td valign="top">
                <div style="float: left; vertical-align: top; text-align: left">
                    <img src="../../Content/images/user-info.gif" alt="User Infor" />
                    <span class="Label">Welcome </span><span class="HeaderLabelText">@Model.UserLevel</span>
                </div>
                <div>
                    <div style="float: left; width: 100%;">
                        <u><span class="Label">Currently Editing:</span> </u>
                    </div>
                    <div style="float: left; width: 100%;">
                        <span class="Label">Company:</span> <span class="HeaderLabelText">@Model.SelectedManageCompanyID</span>
                    </div>
                    <div style="float: left; width: 100%;">
                        <span class="Label">User:</span> <span class="HeaderLabelText">@Model.UserLoginName</span>
                    </div>
                </div>
            </td>
            <td>
            </td>
            <td>
                @{Html.RenderPartial("SearchDDLPartialViews", Model);}
            </td>
        </tr>
        <tr>
            <td colspan="4">
                @RenderBody()
            </td>
        </tr>
    </table>
</body>
</html>

/Shared/UserPartialView.cshtml

@model XYZNameSpace.Models.User
<div style="float: left; margin-left: .5em;">
    <img src="../../Content/images/user-info.gif" alt="User Infor" />
    <span style="font-weight: bold; float: left;">Welcome </span>
</div>

OK, i was able to select one item from each dropdown but when i click on image button at search Action in home control, the BaseViewModel has nothing other than selectedIDs, so when action is trying to display SearchResults view back, them _Layout.cshtml throughs error saying there nothing in lists that are used by dropdowns.

so how do we persist this information for every request…?

  • 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-01T16:41:59+00:00Added an answer on June 1, 2026 at 4:41 pm

    Quick solution is store the List < SelectListItem > or the viewmodel itself in session and reintroduce them to the view every time you return the viewmodel. However for cloud based solutions, same concept, but you’ll need to use other caching storage such as appfabric, memcache or other addons allowed by your PaaS.

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

Sidebar

Related Questions

I am working on a web app using C# and asp.net I have been
So, I'm working in a hybrid web app/mvc application. Trying to do all new
I have a web app that I am building using asp mvc with nhiberante
Im working on an web app using c#. I have in my code the
I have a Spring MVC/3.0 app using tiles as it's view, this is working
I am currently working on a web app using Wicket and started using jQuery
Im working on an iphone web app using JQTouch , im just wondering what
I am working on an iPhone mobile web app using jqtouch to make it
I am working on a web app and I am using JSF and JPA(EclipseLink).
I'm working on a database for a small web app at my school using

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.