ViewBag用于视频上传

本文关键字:视频 用于 ViewBag | 更新日期: 2023-09-27 18:08:36

我正在使用来自codeproject http://www.codeproject.com/Tips/1011040/Upload-and-Delete-Video-File-to-Microsoft-Azure-Bl的样本

我创建了一个索引。以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>}

和我的控制器类是:

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错误。问题是-如何在这个索引中正确调用add方法。cshtml文件?

ViewBag用于视频上传

您的控制器称为BlobsController,因此这会给您/blobs/{action}的路由与默认路由,但是在您的视图中,您的操作正在寻找一个名为blob的控制器。要么更改控制器的名称

public class BlobController : Controller
{
    //...
}

或者更新你的视图以使用正确的控制器名。

Html.BeginForm("Add", "Blobs", FormMethod.Post, new
{enctype = "multipart/form-data" }))