Search code examples
asp.netasp.net-mvcrazorneatupload

ASP.NET control with MVC's Razor engine


I'm using ASP.NET MVC 3 with the Razor template engine for my website. I currently allow files uploads like this:

<form action="/File/Upload" method="post" enctype="multipart/form-data">
    <label for="file">Upload a file:</label>
    <input type="file" name="file" id="file" /> 
    <input type="submit" name="submit" value="Submit" />
</form>

But would like to use a 3rd party control such as NeatUpload, which allows a progress bar, multi file selection, etc.

In the documentation, they show the control being used like this:

<%@ Register TagPrefix="Upload" Namespace="Brettle.Web.NeatUpload"
         Assembly="Brettle.Web.NeatUpload" %>
<Upload:InputFile id="inputFileId" runat="server" />

with some code-behind.

The Razor engine understandably doesn't like this syntax. Is there another way to use 3rd party controls with it, or am I out of luck?


Solution

  • Third party controls that work with Web Forms aren't really compatible with a pure MVC application. Having said that, you may be able to work with a hybrid type of solution, leveraging Web Forms in certain places and MVC in others. It's not something I would do personally, but you could.

    See this post by Scott Hanselman which goes into some detail about doing just that.

    Using a web forms control on a Razor page just won't work though.