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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:14:28+00:00 2026-05-26T13:14:28+00:00

Let me explain my problem: I have four tables created as objects using Entity

  • 0

Let me explain my problem:

I have four tables created as objects using Entity Framework.
I have added a repository class to the Entity Model to add/remove/get/query stuff that I need.

 public class YPlaylistRepository
{

    private aspnetdbEntities entities = new aspnetdbEntities();
    //
    // Query Methods
    public IQueryable<Song> FindAllSongs()
    {
        return entities.Songs;
    }

    public IQueryable<TopTenFav> FindAllTopTen()
    {
        return entities.TopTenFavs;
    }

    public IQueryable<Genre> FindAllGenres()
    {
        return entities.Genres;
    }
 }

and so on…

My Index View is divided into some partial Views such as:

 @{
ViewBag.Title = "Home Page";
  }

 @Html.Partial("_PartialPlayer")
 <div>

  @Html.Partial("_PartialOtherFav")
 <div id="topTenContainer" style="float: left; width:450px;margin-top:49px;">
 @Html.Partial("_PartialTopTenFav")
 @Html.Partial("_PartialCurrentFav")

let say that in my _PartialOtherView i have a form where i want to type in some info and add it to a database:

 @model  yplaylist.Models.TopTenFav

 <div id="otherFavContainer">

 <div id="txtYoutubeLinkContainer">
 @using (Html.BeginForm("AddTopTenFav", "Home", FormMethod.Post, new { id = "AddTopTenFavForm" }))
 {

    <span id="youTubeLinkSpan">Youtube Link</span>
    <div>
        @Html.TextBoxFor(modelItem => modelItem.YoutubeLink, new { id ="youTubeLinkTxt" })
    </div>
    <span id="youTubeNameSpan">Song Title</span>
    <div>
        @Html.TextBoxFor(modelItem => modelItem.Title,new{id="youTubeNameTxt"} )
    </div>

 <button type="submit" name="btnCreateComment" value="">submit</button>
 }

 </div>
 </div>

 </div>

This request goes to controller:

 public class HomeController : Controller
{
    private YPlaylistRepository repository = new YPlaylistRepository();


    public ActionResult Index()
    {
        var topTenList = repository.FindAllTopTen().ToList();
        return View(topTenList);
    }

    public ActionResult About()
    {
        return View();
    }

    public ActionResult Users()
    {

        return View();
    }

    [HttpPost]
    public ActionResult AddTopTenFav(TopTenFav topTen)
    {

        topTen.Date = DateTime.Now;
        topTen.UserName = User.Identity.Name;
        repository.AddTopTen(topTen);
        repository.Save();
        return RedirectToAction("Index");
    }

}

how would I solve the issue of passing the right model to my index View when all of my partialviews would be dealing with different models.. i’ve tried to create a class that encapsulates all my models, but this just created further problems because my entity object returned particular types not found in my “HomeViewModel” such as list of objects and so on

this really confuses me, how would I resolve this, i’m sure it can be done somehow, but whats the right way? thanks in advance

  • 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-26T13:14:29+00:00Added an answer on May 26, 2026 at 1:14 pm

    I think (from my understanding of the problem) that what you need is to pass a view model to the index view containing any further models such as:

    public class IndexModel
    {
        public TopTenFav TopTenFavourites { get; set; }
    
        ...
    }
    

    Then in the Index() action you would return the view model:

    public ActionResult Index()
    {
        var topTenList = repository.FindAllTopTen().ToList();
        return View(new IndexModel() { TopTenFavourites = topTenList});
    }
    

    Then the view would pass this model to/from the partial view as:

    @Html.Partial("_PartialTopTenFav", Model.TopTenFavourites)
    

    The submission of the form in the partial view should call the AddTopTenFav() and correctly pass the TopTenFav model to the action.

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

Sidebar

Related Questions

I have a problem calling a static method from a class. Let me explain
I have this alogirthm problem, in terms of creating mysql tables, let me explain
I have interesting problem. I need to make tables in columns. Let me explain.
Let me explain about my problem: I have a wpf form with few controls.
let me explain my problem. I have a mouseout event assigned to a div
Let me explain the problem in detail. I have a main git branch on
I have problem with testing django apps grouped in subfolder. Well, let me explain
I have a problem with my project, let me explain a moment here and
It might sound unnecessary, but let me explain my problem first. Probably then it
I'm struggling with add_custom_command. Let me explain the problem in detail. I've these set

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.