第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

mvc3上傳文件問(wèn)題

mvc3上傳文件問(wèn)題

呼啦一陣風(fēng) 2018-12-07 03:57:44
@using (Html.BeginForm(new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(true) <fieldset> <legend>Question</legend> <div class="editor-label"> @Html.LabelFor(model => model.Title) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.Title, new { style = "width: 400px" }) @Html.ValidationMessageFor(model => model.Title) </div> <div class="editor-label"> 添加問(wèn)題圖片: </div> <div class="editor-field"> 選擇上傳文件:<input name="file" type="file" id="file" /> </div> <p> <input type="submit" value="Create" /> </p> </fieldset> } controller: // POST: /Question/Create Question question, [HttpPost] public ActionResult Create(Question question, HttpPostedFileBase file) { try { if (ModelState.IsValid) { if (file !=null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Resources"), fileName); file.SaveAs(path); QuestionResource resource = new QuestionResource(); resource.Url = path; question.Resources.Add(resource); } unitOfWork.QuestionRepository.Insert(question); unitOfWork.Save(); return RedirectToAction("Index"); } } catch(Exception ex) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", question.Title + " " + question.Description + " " + file.ContentLength + " " + ex.Message + " Unable to save changes."); } return View(question); } 在控制器中:HttpPostedFileBase file獲取不到上傳的文件。調(diào)試顯示null。 ? 如何獲取到上傳的文件?謝謝
查看完整描述

11 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

你 這樣 讀取this.HttpContext.Request.Files。不要加到參數(shù)里。

查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
蝴蝶不菲

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

打不開(kāi)。一閃就消失了

查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
慕森王

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊

@二手 程序員: 那圖片上傳成功了嗎

查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

@二手 程序員: 都打不開(kāi)??博客園其他頁(yè)面能打開(kāi)嗎?

查看完整回答
反對(duì) 回復(fù) 2019-01-21
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

@二手 程序員: 我這邊打開(kāi)很快啊,你再試試吧

查看完整回答
反對(duì) 回復(fù) 2019-01-21
  • 11 回答
  • 0 關(guān)注
  • 401 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)