1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > asp.net mvc文件上传

asp.net mvc文件上传

时间:2020-11-10 04:56:24

相关推荐

asp.net mvc文件上传

文件上传到文件夹下:

@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>)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。