خرید بک لینک

Vote count: 0

Here is my model class that is just working with text data right now. How would I alter it to have the image field created in the DB

using System;
using System.Data.Entity;

namespace BizzCoect.Models
{
    public class Post
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public DateTime ReleaseDate { get; set; }
        public string Genre { get; set; }
        public decimal Price { get; set; }
    }

public class PostDBContext : DbContext
{
    public DbSet<Post> Posts { get; set; }
}
}

Following is the controller

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using BizzCoect.Models;

namespace BizzCoect.Controllers
{
    public class PostsController : Controller
    {
        private PostDBContext db = new PostDBContext();



// GET: Posts
        public ActionResult Index()
        {
            retu View(db.Posts.ToList());
        }

    // GET: Posts/Details/5
    public ActionResult Details(int? id)
    {
        if (id == null)
        {
            retu new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Post post = db.Posts.Find(id);
        if (post == null)
        {
            retu HttpNotFound();
        }
        retu View(post);
    }

    // GET: Posts/Create
    public ActionResult Create()
    {
        retu View();
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price")] Post post)
    {
        if (ModelState.IsValid)
        {
            db.Posts.Add(post);
            db.SaveChanges();
            retu RedirectToAction("Index");
        }

        retu View(post);
    }

    public ActionResult Edit(int? id)
    {
        if (id == null)
        {
            retu new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Post post = db.Posts.Find(id);
        if (post == null)
        {
            retu HttpNotFound();
        }
        retu View(post);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,Genre,Price")] Post post)
    {
        if (ModelState.IsValid)
        {
            db.Entry(post).State = EntityState.Modified;
            db.SaveChanges();
            retu RedirectToAction("Index");
        }
        retu View(post);
    }

    // GET: Posts/Delete/5
    public ActionResult Delete(int? id)
    {
        if (id == null)
        {
            retu new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Post post = db.Posts.Find(id);
        if (post == null)
        {
            retu HttpNotFound();
        }
        retu View(post);
    }

    // POST: Posts/Delete/5
    [HttpPost, ActionName("Delete")]
    [ValidateAntiForgeryToken]
    public ActionResult DeleteConfirmed(int id)
    {
        Post post = db.Posts.Find(id);
        db.Posts.Remove(post);
        db.SaveChanges();
        retu RedirectToAction("Index");
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            db.Dispose();
        }
        base.Dispose(disposing);
    }
}
}

And here is my View

@model IEnumerable<BizzCoect.Models.Post>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ReleaseDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Genre)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ReleaseDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Genre)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Price)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}

</table>

I want to add the image to this post and I just couldn't figure out a way to do that, the examples on the inteet are mostly related to old versions of MVC and not for MVC5

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 13 ارديبهشت 1395 ساعت: 17:21

صفحه بندی