Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading image in ASP.NET MVC
    text
    copied!<p>I have a Upload form and I want to pass my information such as an Image and some other field but I don't know how can I upload Image ..</p> <p>this is my controller code : </p> <pre><code>[HttpPost] public ActionResult Create(tblPortfolio tblportfolio) { if (ModelState.IsValid) { db.tblPortfolios.AddObject(tblportfolio); db.SaveChanges(); return RedirectToAction("Index"); } return View(tblportfolio); } </code></pre> <p>And this is my view code :</p> <pre><code>@model MyApp.Models.tblPortfolio &lt;h2&gt;Create&lt;/h2&gt; @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;tblPortfolio&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Title) @Html.ValidationMessageFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ImageFile) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.ImageFile, new { type = "file" }) @Html.ValidationMessageFor(model =&gt; model.ImageFile) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Link) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Link) @Html.ValidationMessageFor(model =&gt; model.Link) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } </code></pre> <p>Now I don't know how can I upload Image and save it on server .. how can I set Image name by <code>Guid.NewGuid();</code> ? Or how can I set Image Path ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload