Jquery 如何将文件从视图发送到控制器

Jquery 如何将文件从视图发送到控制器,jquery,json,ajax,model-view-controller,Jquery,Json,Ajax,Model View Controller,我正在尝试在我的应用程序中上载文件 在我看来,我已经做到了 <div> <input id="Excelfile_id" type="file" value="Insert" class="import1" /> </div> <div> <input type="button" id="excelbutton_id" value="import" class="import2" /> </div> 我的控

我正在尝试在我的应用程序中上载文件

在我看来,我已经做到了

<div>
    <input id="Excelfile_id" type="file" value="Insert" class="import1" />
</div>
<div>
    <input type="button" id="excelbutton_id" value="import" class="import2" />
</div>
我的控制器是

public JsonResult import(HttpPostedFileBase excelfile)
{
    if (excelfile.ContentLength == 0 || excelfile == null)
所以,我在控制器中将excelfile变量的错误作为空引用

你能建议一下吗


谢谢

您是否在表单元数据中包含enctype=“multipart/form data”?您需要使用
FormData
。关于示例Myte,我没有将其包含在表单元数据中。Stephen,我将查看该答案,感谢您的建议嗨Stephen,其他答案不太好。
public JsonResult import(HttpPostedFileBase excelfile)
{
    if (excelfile.ContentLength == 0 || excelfile == null)