我是mvc C#的新手,並且卡住了。請告知如何解決此問題。我在添加時遇到錯誤。當我將鼠標懸停在紅色波浪線它說:「並非所有的代碼路徑返回一個值」獲取錯誤:並非所有的代碼路徑都返回一個值
public ActionResult Add(ShapeInputModel dto, FormCollection collection)
{
var model = new GeoRegions();
if (TryUpdateModel(model))
{
var destinationFolder = Server.MapPath("/App_Data/KML");
var postedFile = dto.Shape;
if (postedFile != null)
{
var fileName = Path.GetFileName(postedFile.FileName);
var path = Path.Combine(destinationFolder, fileName);
postedFile.SaveAs(path);
//Save to Database
Db.AddGeoRegions(model);
return RedirectToAction("Index");
}
return View();
}
}
謝謝大家的回答。我從你們所有人那裏學到了很多東西,我很欣賞它,儘管我還有很多東西需要學習。我使用了返回null,並且一切都很完美! – user1382770
請記住,如果您使用'null',則應始終檢查該值,如果方法返回時爲null或不是! – Writwick