Link to home
Start Free TrialLog in
Avatar of hariaspind
hariaspind

asked on

File Upload & Download using ASP.net 3.5 & MVC2.0

I am trying upload file using the below code .But in the controller HTTPPostedFile is coming  as null ? Any solution for this .

<% using (Ajax.BeginForm("Upload", "Attachment", new AjaxOptions { OnSuccess = "ProcessAttachmentUpload", LoadingElementId = "imgAjaxLoader" }, new { enctype = "multipart/form-data" }))

       { %>
        <p>
            <%= Html.HiddenFor(model => model.RequestID)%>
        </p>
             
        <div id="QuestionCreateValidationMessage" class="validation-summary-errors"></div>        
        <table class="Main">          
            <tr>
               <td>    
                        <%= Html.LabelFor(model => model.Name)%>
                        <%= Html.TextBoxFor(model => model.Name, new { @class = "ui-widget-content" })%>
               </td>
            </tr>      
            <tr>
                <td>
                    <input type="file"  name="FileUpload" id="FileUpload" value="Uploadfile"/>
                   
                </td>
            </tr>      
        </table>        
        <p>
            <input type="submit" class="ui-button ui-state-default" id="btnUpload" value="Upload" />
        </p>        
    <% } %>
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hariaspind
hariaspind

ASKER

This tell about uploading using HTML.Beginform.This was already working for me .

I am trying to use
<% using (Ajax.BeginForm("Upload", "Attachment", new AjaxOptions { OnSuccess = "ProcessAttachmentUpload", LoadingElementId = "imgAjaxLoader" }, new { enctype = "multipart/form-data" }))

because i am trying to use the AjaxOptions { OnSuccess = "ProcessAttachmentUpload", LoadingElementId = "imgAjaxLoader" } and display the result through jquery.
It's hard to use Ajax.BeginForm.So Now i am using the HTML.Begin Form ,as in the sample.Works good .
Thanks