1

Sorry if this is obvious, but it is very confusing for me. After specifying model type:

@model MyNamespace.MyModel

Which does not display any error and the path to the MyModel is correct, same is the model name, some of the methods seem not to recognize the Model type as follows:

@Html.Partial("_Title", Model)

Which outputs the following error:

extension methods cannot be dynamically dispatched

Which should not be shown, since the Model type is specified. Also if I am trying to cast it again:

@Html.Partial("_Title", (MyNamespace.MyModel)Model)

Resharper is saying that Cast is redundant, but the error goes away.

What could cause this behavior to an MVC view?

Note: I have other views which have the model defined in the very same way and which are using exactly same partial views, but they are working properly.

I have tried deleting the file and recreating and the errors keep coming back.

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76
  • 1
    Do you have @model MyNamespace.MyModel in your partial view? – Ha Hoang Aug 05 '16 at 16:12
  • @HaHoang no, and I don't need one in the partial view since it needs to be more generic, and also this should not be the problem since the other views are working properly with the same partial views. – meJustAndrew Aug 05 '16 at 16:13
  • Maybe, you need to use the namespace before you call your model. – Ha Hoang Aug 05 '16 at 16:20
  • @meJustAndrew Check [this](http://stackoverflow.com/questions/15391115/what-causes-extension-methods-cannot-be-dynamically-dispatched-here) out! – Steve Morin Aug 05 '16 at 19:04

1 Answers1

1

I'm not sure why you'd need to do that at all. When you call Partial() and don't specify the model, the current model is passed to the Partial :)

The reason this happens is because internally when you pass a model to Partial() MVC copies the current ViewData (including ViewData["Model"]) and passes it to the next partial, if you don't specify the value the current value is used.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • This is a very good point, and it is really helpful, but let's say I need to send only a part of my model, one of it's properties. It still generates the same fake error, and I don't know how to clear it, or why is this happening. I couldn't recreate this on any other view. Thank you very much for your support, it was again, really helpful! – meJustAndrew Aug 18 '16 at 15:25