我还是 Asp .Net MVC 和 C# 的新手。我在学习如何做某些事情时遇到了问题,我遇到了让按钮加载我的视图的问题。我了解到我不需要像通常在 .NET MVC 中那样的事件侦听器,因此我使用@Ajax.ActionLink 作为我的按钮。但是,当我单击按钮时,它不会加载我的视图。我想不通为什么?我无法让按钮加载我的视图。
这就是我所做的。在我的共享文件夹中,我有一个包含按钮的布局页面。我插入了这个按钮:
<li>@Ajax.ActionLink("Res-TestImageExtension","TestImageExtension","TestImageExtension","",App.ViewOptions.appAjaxOptions,App.ViewOptions.blueButtonHtmlAttributes)</li>
在我的控制器文件夹中,我插入了一个控制器,其中包含以下内容:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HexaPod.Controllers
{
public class TestImageExtensionController : Controller
{
// For multiple file select
[HttpPost]
public ActionResult Create(List<HttpPostedFileBase> image)
{
if (image != null)
{
foreach (var item in image)
{
string filePath = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(item.FileName));
item.SaveAs(filePath);
}
}
return PartialView("TestImageExtension");
}
}
}
模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HexaPod.Models
{
public partial class ImageUpload {
public int ID { get; set;}
public string ImagePath {get; set;}
}
}
看法:
@model HexaPod.Models.ImageUpload
@{
ViewBag.Title = "Image Upload";
}
@*
*@
@using (Html.BeginForm("Create", "Profile", FormMethod.Post, new { enctype =
"multipart/form-data", id = "frm_profile" }))
{
@Html.LabelFor(model => model.ImagePath)
@Html.TextBoxFor(model => model.ImagePath, new { type = "file", accept = "image/jpeg, image/jpg"}) @Html.ValidationMessageFor(model => model.ImagePath)
// for multiple file select
@Html.TextBoxFor(model => model.ImagePath, new { type = "file", accept = "image/jpeg, image/jpg", multiple = "multiple" })
}