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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:01:19+00:00 2026-06-01T18:01:19+00:00

I have created a web application in mvc3 and created two partial views one

  • 0

I have created a web application in mvc3 and created two partial views
one having controls two dropdownlist.
second having webgrid which shows data from database.

    partialview1.cshtml
    @model Mapping.Models.SecurityIdentifierMapping

    @using (Html.BeginForm("Mapping", "Home"))
    {
        @Html.DropDownList("SecurityID", Model.PricingSecurityID, "-- Select SecurityID --")
        <br />    
        @Html.DropDownList("CUSIPID", Model.PricingSecurityID, "-- Select CUSIPID --")
        <br />
        <button type="submit">Map</button>
    }

    partialview2.cshtml
    @model IEnumerable<Mapping.Models.SecurityIdentifierMapping>

    @{
        ViewBag.Title = "Mapping";
        WebGrid grid = null;
        if (Model.Count() > 0 ){
        grid = new WebGrid(source: Model,
                                defaultSort: "Id",
                                canPage: true,
                                canSort: true,
                                rowsPerPage:20);
        }
    }


    <h2>Mapping</h2>


    @if (grid != null)
    {
    @grid.GetHtml(
                    tableStyle: "grid",
                    headerStyle: "head",
                    alternatingRowStyle: "alt",
                    columns: grid.Columns(
                                                grid.Column("", header: null, format: @<text>@Html.ActionLink("Edit", "Edit", new { id = (int)item.id })  @Html.ActionLink("Delete", "Delete", new { id = (int)item.id })</text>),
                                                grid.Column("PricingSecurityID"),
                                                grid.Column("CUSIP")
                                              )

                    )
    }
    <br />
    <p>
        @Html.ActionLink("Back", "Index")
    </p>

    in index.cshtml


    <div>
    @Html.Partial("_ControlsPartial",)
    </div>

    <div>
    @Html.Partial("_WebGridPartial")
    </div>

inside Indexcontroller.cs in Index()

     public ActionResult Index()
            {
//FOR POPULATE DROPDOWN
                //SecurityIdentifierMapping objModel = new SecurityIdentifierMapping();
                //objModel.PricingSecurityID = objRepository.GetPricingSecurityID();
                //objModel.CUSIP = objRepository.GetCUSIP();
                //return View(objModel);

              //FOR  DISPLAY DATA IN WEBGRID
                return View(dbContext.SecurityIdentifierMappings);
            }

here problem is webgrid partial view is having@model IEnumerable<Mapping.Models.SecurityIdentifierMapping>
and
controlpartilview is having @model Mapping.Models.SecurityIdentifierMapping

so HOW CAN I CREATE A VIEWMODEL.cs A NEW CLASS WHICH WILL HAVE BOTH MODELS AND HOW CAN I WRITE IT IN INDEX(() SO THAT THAT METHOD WILL POPULATE DROPDOWN ALSO AND SHOW DATA IN WEBGRID ALSO ?

  • 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-01T18:01:21+00:00Added an answer on June 1, 2026 at 6:01 pm

    Why not just create a custom View Model class that contains two properties:

    public class SecurityIdentifierMappingViewModel
    {
        public IEnumerable<SecurityIdentifierMapping> MappingList {get; set; }
        public SecurityIdentifierMapping Mapping {get; set; }
    }
    

    Then you can pass this custom view model to the Index view and the corresponding property as the view model of each of the partials

    EDIT

    Your Index action would then look something like this:

    public ActionResult Index()
    {
        // single mapping
        var mapping = new SecurityIdentifierMapping();
        maping.PricingSecurityID = objRepository.GetPricingSecurityID();
        mapping.CUSIP = objRepository.GetCUSIP();
    
        var viewModel = new SecurityIdentifierMappingViewModel
        {
            Mapping = mapping,
            MappingList = dbContext.SecurityIdentifierMappings.ToList()
        };
    
        return View(viewModel);
    }
    

    And in Index.cshtml:

    @model SecurityIdentifierMappingViewModel
    
    <div>
        @Html.Partial("_ControlsPartial", Model.Mapping)
    </div>
    
    <div>
        @Html.Partial("_WebGridPartial", Model.MappingList)
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a web application in mvc3 and created two partial views one
i have created an mvc3 web application that uses forms based authentication. one part
I have created an MVC3 application and added cutomerrors attribute on in web.config. It
I have created a Web Application in asp.net 2.0. which is working fine on
I have created a web application using ASP.NET MVC3 in Visual studio (no SQL
I have created blank Asp.Net-MVC 3 web application and want to write my own
I have created a web application using Visualstudio 2008 using C# on my computer.
I have created a web application with a Silverlight project embedded in it, using
I have created a site collection inside a web application with user A as
I have the following scenario. I have created an ASP.NET web application (framework 3.5)

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.