I have a HomeController with this code:
public ActionResult Index()
{
IndexModel m = new IndexModel();
m.Test = "someString";
m.LoginModel = new ViewLoginModel();
m.LoginModel.Test = "FromLogin";
return View("Login", m);
}
And in my Index.cshtml, I have this:
@model IndexModel
//bunch of HTML
@Html.Partial("_Login", Model.LoginModel)
And in the _Login.cshtml, this:
@model ViewLoginModel
//bunch of HTML
@Html.LabelFor(model => model.Test)
Basically, what I want to do is to have a separate model for a partial window (login) in my home page, and this model can be or not a child of the ViewIndexModel (ideally this shouldn't even exist). I'm trying to access the variables and write/use them in the partial view, but it doesn't work - it displays the property's name instead.
In the partial view "_Login", the intellisense also doesn't work for some reason (VS2013), although the @Html.BeginForm and stuff is working, but I can't access the model's properties.
What am I doing wrong, how do I fix this?
Also, is there a difference between these two?
@Html.Partial("~/Views/Home/_Login.cshtml")
@Html.Partial("Login")
It seems when I'm using #2 the function "Login" is being called in my HomeController, not sure why...