MVC3文件上传按钮 [英] MVC3 File upload button

查看:83
本文介绍了MVC3文件上传按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手希望有人可以帮助我。

在弹出模式的项目中,我有一个文本框和文件控件(以及上传按钮)。



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();"/>







HomeController.cs

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





所以这里给出了name =command来处理按钮的提交类型(上传和保存按钮)。这里的问题是HttpPostedFileBase文件返回null。当我为上传按钮提供name =file值时,当我点击Upload按钮时没有执行任何动作,断点没有按下方法。



请提供一些建议并指导我以正确的方式解决此问题。



提前致谢。



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.

推荐答案

这篇关于MVC3文件上传按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆