T4MVC: Strongly typed partial?

198 views Asked by At

I'm using T4MVC in my MVC 5 website. In a view, I have something like:

@Html.Partial(MVC.Shared.Views.ViewNames.Foo, Model.FooBar)

The Foo view expects a certain type, which is defined with @model, but Model.FooBar might have a different type. This error is not detected until runtime.

Is there a way to use T4MVC to render the partial with a typed method, like we can use ActionLinks, maybe something like:

@Html.Partial(MVC.Shared.Views.Foo(Model.FooBar))  // Error: Foo() expects Argument of type ...
1

There are 1 answers

1
David Ebbo On

Short answer is that T4MVC currently doesn't support fully strong typing this scenario.

It's something that could conceivably be done, but it would present challenges. Specifically, T4MVC would need to parse the view to determine the model type. Currently, it never parses views, but only detects their existence.