In my _Shared
I have a PartialView call _rodape.cshtml
but now it will need to receive a ViewModel
Since I do not want to create an Action on each Controller , I thought about creating a Controller named _Rodape
, and all others Controller inherit from this:
It even ran, but I can not send my ViewModel .
How it was: _Shared
@{Html.RenderAction("_Rodape"); }
HomeController
namespace WmbMVC.Controllers
{
[VerificarSkin]
public class HomeController : RodapeController
{
private readonly WMBContext db = new WMBContext();
public ActionResult Index()
{
RodapeController:
public class RodapeController : Controller
{
public PartialViewResult _Rodape()
{
using (WMBContext db = new WMBContext())
{
var cliente = db.Clientes.Find(IDC);
var rodapeVM = new RodapeViewModel
{
Cliente = cliente
};
return PartialView("_skin300/_rodape");
}
}
}
When in _rodape.cshtml
I try to use @Model.AlgumaCoisa
it gives the error:
System.NullReferenceException:
I thought of sending direct from _shared
o ViewModel to Partial , something like:
@{Html.RenderAction("_Rodape", new RodapeViewModel()); }
But I need a controller to run a variety of business logic. How to send the ViewModel to a PartialView within a Shared