Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to MVC hope someone can help me out.
In my project on a pop up modal I have a textbox and file control (along with Upload button).

Index.cshtml

@using (Ajax.BeginForm("AddLoadDtl", "LoadDetail", FormMethod.Post, new AjaxOptions { HttpMethod = "post", UpdateTargetId = "AddLoadDialog", LoadingElementId = "AdddivProcessing", OnSuccess = "ResetControls" }, new { id = "AddLoadDtlForm", enctype = "multipart/form-data" }))
{

<div id="AddLoadDtl" style="background: #fef9f3; color: #5a5a5a; font-family: Arial; font-size: 9pt;">
        <table style="width: 100%; background: #fef9f3; color: #5a5a5a; font-family: Arial; font-size: 9pt;">
            <tr>
                <td>
                    <div class="box-con" style=" background: #fef9f3; color: #5a5a5a; font-family: Arial; font-size: 9pt;">
                        <table style="width: 100%;">
                            <tr>
                                <td width="20%">
                                    <span>Number</span>
                                    <br />
                                    @Html.Hidden("MarkNumber", (string)ViewBag.MarkNumber)
                                    @Html.TextBoxFor(m => m.Number, new { maxlength = 6, @class = "MarkDirty ValidateMaxLength" })
                                </td>   
</tr>                             
<tr>
                                <td >
                                    <span>Upload</span>
                                    <br />
                                    <input type="file" id="fileToUpload" name="file" />                            
                                    
                                    <input type="submit" name="command" id="btnSubmit" value="Upload" /><span class="field-validation-error" id="spanfile"></span>
                                </td>
                            </tr>

<input id="btnSave" type="submit" name="command" value="Save"  önclick="OnSubmit();" />
                                    <input id="btnCancel" type="button" value="Cancel"  önclick="OnCancel();"/>


C#
HomeController.cs

public ActionResult AddLoadDtl(Load LoadModel, HttpPostedFileBase file, string command)
        {
if(command == "Upload")
{
 ....
}
else
{
...
}
}


So here name="command" is given in order to handle the "submit" type for the buttons (Upload and Save button). The issue here is HttpPostedFileBase file is returning null. When I give name="file" value for the Upload button then there is no action performed when I click on Upload button, breakpoint is not hitting the method.

Please provide some suggestion and direct me in the right way to get this issue resolve.

Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900