文件上传到文件夹下:
@using (Html.BeginForm("FileUp","Home",FormMethod.Post,new { enctype = "multipart/form-data" }))
{
<div>
<label>头像</label>
<input type="file" name="Icon"/>
</div>
<div>
<input type="submit" value="上传"/>
</div>
}
后台代码:
[HttpPost]
public ActionResult FileUp(goods gds, HttpPostedFileBase Icon)
{
Icon.SaveAs(Server.MapPath("~/IMG") +"\\" + Guid.NewGuid().ToString() + Path.GetExtension(Icon.FileName));
return View();
}
修改成功提示并跳转:
return Content("<script>alert('修改成功');location.href='/Home/Test'</script>");
超链接:
@Html.ActionLink("详情","Details",new { id=item.goodsid})
男女性别:
@Html.RadioButton("testSex", true, Model.testSex == true)<span>男</span>
@Html.RadioButton("testSex", false, Model.testSex == false)<span>女</span>
修改:
db.Entry<Student>(stu).State = System.Data.Entity.EntityState.Modified;
return db.SaveChanges();
下拉框后台:
var grade = StudentManager.GetSelectAll().GroupBy(p => p.StuGrade).Select(p => new { GradeID = p.Key, GradeName = p.Key });
ViewBag.DDLGrade = new SelectList(grade, "GradeID", "GradeName");
return View(stus);
下拉框前台:
@Html.DropDownList("StuGrade", ViewBag.DDLGrade as IEnumerable<SelectListItem>)