我正在使用codeproject http://www.codeproject.com/Tips/1011040/Upload-and-Delete-Video-File-to-Microsoft-Azure-Bl
中的示例我已经创建了一个index.cshtml
@model List<string>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Add", "Blob", FormMethod.Post, new
{enctype = "multipart/form-data" }))
{
<div>
<input type="file" name="pic" id="pic" />
<input type="submit" value="Upload Now" id="s1" />
</div>
}
<ul>
@foreach (var item in Model)
{
<li>
<input type="button" name="b1" id="b1"
value="Delete"
onclick="Remove('@item')" />
<video src="@item" height="200" width="200" controls />
</li>
}
</ul>
@section scripts{
<script>
function Remove(x) {
alert(x);
var uri = "/Blob/remove";
$.post(uri, { name: x }, function (y) {
window.location.href = "/blob/index";
alert(y);
});
}
</script>}
我的Controller类是:
public class BlobsController : Controller
{
//
// GET: /Blobs/
BlBlobs objbl = new BlBlobs();
public ActionResult Index()
{
//return View();
return View(objbl.GetBlobList());
}
[HttpPost]
public ActionResult Add(HttpPostedFileBase pic)
{
objbl.AddBlob(pic);
return RedirectToAction("Index");
}
[HttpPost]
public string Remove(string name)
{
objbl.DeleteBlob(name);
return "Blob Removed Successfully";
}
}
这给了我非常好的浏览/上传表单,但上传点击失败,出现404错误。问题是 - 如何在这个index.cshtml文件中正确调用add方法?
答案 0 :(得分:1)
您的控制器名为BlobsController
,因此会为您提供/blobs/{action}
的默认路线,但在您的视图中,您的操作正在寻找名为blob
的控制器。更改控制器的名称
public class BlobController : Controller
{
//...
}
或更新您的视图以使用正确的控制器名称。
Html.BeginForm("Add", "Blobs", FormMethod.Post, new
{enctype = "multipart/form-data" }))