Przesyłanie obrazu w ASP.NET MVC
Mam formularz przesyłania i chcę przekazać moje informacje, takie jak obraz i inne pola, ale nie wiem, jak mogę przesłać obraz ..
to jest mój kod kontrolera:
<code>[HttpPost] public ActionResult Create(tblPortfolio tblportfolio) { if (ModelState.IsValid) { db.tblPortfolios.AddObject(tblportfolio); db.SaveChanges(); return RedirectToAction("Index"); } return View(tblportfolio); } </code>
A to jest mój kod widoku:
<code>@model MyApp.Models.tblPortfolio <h2>Create</h2> @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(true) <fieldset> <legend>tblPortfolio</legend> <div class="editor-label"> @Html.LabelFor(model => model.Title) </div> <div class="editor-field"> @Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title) </div> <div class="editor-label"> @Html.LabelFor(model => model.ImageFile) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.ImageFile, new { type = "file" }) @Html.ValidationMessageFor(model => model.ImageFile) </div> <div class="editor-label"> @Html.LabelFor(model => model.Link) </div> <div class="editor-field"> @Html.EditorFor(model => model.Link) @Html.ValidationMessageFor(model => model.Link) </div> <p> <input type="submit" value="Create" /> </p> </fieldset> } </code>
Teraz nie wiem, jak mogę przesłać obraz i zapisać go na serwerze. Jak mogę ustawić nazwę obrazu wedługGuid.NewGuid();
? Lub jak mogę ustawić ścieżkę obrazu?