Bild wird in ASP.NET MVC hochgeladen

Ich habe ein Upload-Formular und möchte meine Informationen wie ein Bild oder ein anderes Feld weitergeben, weiß aber nicht, wie ich ein Bild hochladen kann.

Das ist mein Controller-Code:

<code>[HttpPost]
        public ActionResult Create(tblPortfolio tblportfolio)
        {
            if (ModelState.IsValid)
            {
                db.tblPortfolios.AddObject(tblportfolio);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(tblportfolio);
        }
</code>

Und das ist mein Ansichtscode:

<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>

Jetzt weiß ich nicht, wie ich ein Bild hochladen und auf dem Server speichern kann. Wie kann ich den Bildnamen nach festlegen?Guid.NewGuid(); ? Oder wie kann ich den Bildpfad einstellen?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage