I'm working with MVC3 with Razor for first time, and I have a partial view which is used in many other places and has no model. And now I need it, can I create an optional model? If it is passed, then I'll use it, otherwise I'll leave the default behavior.
[Update]
I'd like to call it like this:
@Html.Partial("_myPartialView")
or this:
@Html.Partial("_myPartialView", "Some string")
(the partial view model is a string)
Is this possible?
@model FooBar
@if (Model != null)
{
<div>@Model.SomeProperty</div>
}
else
{
<div>No model passed</div>
}
UPDATE:
After showing the way you are calling your partial, here's what you could do:
@Html.Partial("_myPartialView", null, new ViewDataDictionary())
@Html.Partial("_myPartialView", "Some string")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With