razor 写入html标记,如何在Razor中编写“ Html.BeginForm”
生活随笔
收集整理的這篇文章主要介紹了
razor 写入html标记,如何在Razor中编写“ Html.BeginForm”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
泛舟湖上清波郎朗
以下代碼可以正常工作:@using (Html.BeginForm("Upload", "Upload", FormMethod.Post,?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new { enctype = "multipart/form-data" })){? ? @Html.ValidationSummary(true)? ?
? ? ? ? Select a file ? ? ? ? ? ? }并按預期生成:? ??? ? ? ? ? ? Select a file ? ? ? ? ? ? 在另一方面,如果你正在寫其他的服務器端結構的上下文中的代碼,如if或foreach您應該刪除@之前using。例如:@if (SomeCondition){? ? using (Html.BeginForm("Upload", "Upload", FormMethod.Post,?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new { enctype = "multipart/form-data" }))? ? {? ? ? ? @Html.ValidationSummary(true)? ? ? ? ? ? ? ? ? ? Select a file ? ? ? ? ? ? ? ? ? ? ? ? }}就您的服務器端代碼而言,這是繼續的方法:[HttpPost]public ActionResult Upload(HttpPostedFileBase file)?{? ? if (file != null && file.ContentLength > 0)?? ? {? ? ? ? var fileName = Path.GetFileName(file.FileName);? ? ? ? var path = Path.Combine(Server.MapPath("~/content/pics"), fileName);? ? ? ? file.SaveAs(path);? ? }? ? return RedirectToAction("Upload");} 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的razor 写入html标记,如何在Razor中编写“ Html.BeginForm”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 热血江湖游戏窗口化的方法
- 下一篇: jquery html 片段,十条jQu