Registering custom web control inside mvc view?

I am in the middle of a project where I am migrating some code for a website from WebForms to MVC - unfortunately there is not enough time to do everything at once, so I will have to make some ... not so pretty solutions.

I am facing problems with a custom control I wrote that inherits from the standard GridView control

namespace Controls {
    public class MyGridView : GridView { ... }
}

      

I added the web.config file as usual:

<configuration>
...
   <system.web>
   ...
      <pages>
      ...
         <controls>
         ...
         <add tagPrefix="Xui" namespace="Controls"/>
         </controls>
      </pages>
   </system.web>
</configuration>

      

Then on the MVC View:

<Xui:MyGridView ID="GridView1" runat="server" ...>...</Xui:MyGgridView>

      

However, I am getting a parser error stating that the control could not be found. I suspect it has to do with mixing MVC and WebForms, however I / got the impression that such a mix should be possible, is there any tweak to do this? I understand that this solution is far from ideal, but there is no time to "do the right thing".

thank


Edit:
I forgot to add that I already tried using this, with the same result.

Also I would be uncomfortable with using it on multiple pages, so adding it to the web.config would be ideal, however if there is a solution that only works on individual pages then that would be more than acceptable as well.

0


source to share


1 answer


Can't you use the <% @ Register%> directive directly in the view? Why do this in web.config if it won't be used throughout the application? I'm not sure if this will work as I haven't spent a lot of time on ASP.NET MVC, but you can try.



0


source







All Articles