Let’s say I have the three following action methods in an MVC3 controller:
public ActionResult ShowReport()
{
return View("ShowReport");
}
[PageOptions(OutputFormat = OutputFormat.Web)]
public ActionResult ShowReportForWeb()
{
return View("ShowReport");
}
[PageOptions(OutputFormat = OutputFormat.Pdf)]
public ActionResult ShowReportForPdf()
{
return View("ShowReport");
}
In my Razor view, I’d like to be able to tell:
- Whether the PageOptions attribute was attached to the calling action method.
- If it was, what the value of its OutputFormat property is.
Here’s some pseudo-code illustrating what I’m trying to do:
@if (pageOptions != null && pageOptions.OutputFormat == OutputFormat.Pdf)
{
@:This info should only appear in a PDF.
}
Is this possible?
LeffeBrune is correct, you should pass that value as part of your ViewModel
Just create an enum
And use this in your ViewModel
And then assign the value in your Controller actions