我有一个像这样的视图
<td><a href="@Url.Action("AddingAnnouncement", new { id = item.ScheduleID,name =item.EmployeeID})" class="btn btn-warning"><i class="fas fa-plus"></i> Adding Announcement</a></td>
获取id部分时我得到了它,但名称部分我无法获得控制器的名称部分,当我转到该链接时,它传递了id和name是,但是控制器无法获得Name id或值名字我怎么也能得到呢?
这是我的控制器
[Authorize(Roles = "Faculty")]
public ActionResult AddingAnnouncement(int? name)
{
return View (name);
}
[HttpPost]
public ActionResult AddingAnnouncement(int? id,int? name, Announcement model, HttpPostedFileBase file)
{
Announcement annc = new Announcement();
var ErrorMessage = "";
var filesize = 25000;
foreach (var item in model.File)
{
try
{
var supportedTypes = new[] { "txt", "doc", "docx", "pdf", "xls", "xlsx" };
var fileExt = System.IO.Path.GetExtension(file.FileName).Substring(1);
if (!supportedTypes.Contains(fileExt))
{
ErrorMessage = "File Extension Is InValid - Only Upload WORD/PDF/EXCEL/TXT File";
return Content(ErrorMessage);
}
else if (file.ContentLength > (filesize * 1024))
{
ErrorMessage = "File size Should Be UpTo " + filesize + "KB";
return Content(ErrorMessage);
}
else
{
annc.MainAnnouncement = model.MainAnnouncement;
annc.EmployeeID = name;
annc.DatePosted = DateTime.Now;
annc.ScheduleID = id;
annc.DocumentFile = ConverToByte(item);
annc.FileType = file.ContentType;
annc.FileName = file.FileName;
db.Announcements.Add(annc);
string path = Path.Combine(Server.MapPath("~/Files/TeachingMaterials/"), Path.GetFileName(file.FileName));
file.SaveAs(path);
db.SaveChanges();
}
}
catch (Exception ex)
{
ErrorMessage = "Upload Container Should Not Be Empty or Contact Admin";
return Content(ErrorMessage);
}
}
return RedirectToAction("FacultySchedule");
}
答案 0 :(得分:0)
NVm觉得该死,我从没想过它是如此简单,我哈哈XD
在get控制器上
[Authorize(Roles = "Faculty")]
public ActionResult AddingAnnouncement(int? name)
{
Announcement model = new Announcement();
model.EmployeeID = name;
return View(model);
}
然后在帖子中
[HttpPost]
public ActionResult AddingAnnouncement(int? id,Announcement model, HttpPostedFileBase file)
{
}