My situation is that I have a layout page, as part of that layout page there is a main section view where certain elements on that view are called from a table/model using a foreach loop. These are references to a certain course and are called using the controller based on the URL as follows:
public ActionResult Course_page(string id)
{
string abbrev = id;
var cpage = from c in db.Course_page
select c;
if (!String.IsNullOrEmpty(abbrev))
{
cpage = cpage.Where(x => x.abbrev.Contains(abbrev));
}
return View(cpage);
}
This works fine by itself. However on the same layout there is also a login and register ajax form in a navbar and footer view both rendered by the original layout page.
So in Navbar for example there is an Ajax.Beginform and then the form itself is called currently with Html.Partial which calls the form from a page with the form HTML.
I have been trying to use solutions to my problem from the following question:
However I haven't had much success. I did try and create a viewmodel containing all 3 models that need to be present, but I couldn't work out how to integrate that into my page given my controller above. When I referenced the viewmodel in the course page foreach loop there was always a problem and I think it was related to what I was doing in my controller or possibly the way all the pages are setup. So I've been trying the RenderPartial method in the thread above. Changing my @Html.Partial references to the login and register forms present in the navbar and footer respectively however that doesn't seem to work either. I get a 'models' do not exist in this context when I change:
@Html.Partial("_login");
to...
@{Html.RenderPartial("_login", Models.LoginViewModel);
}
Bearing in mind that the LoginViewModel does exist in the relevant models namespace.
I am an absolute beginner, so it might be I am just not understanding some basic concept here. I've gone through literally every tutorial I can find and every question I can find on Viewmodels and the likes but I still can't resolve my particular problem. So I would appreciate anyone steering me in the right direction regarding my problem? Thanks.