0

有没有人知道在 mvc asp.net 中使用 CRUD 时如何上传,以便我的图像将上传到我的标题中,无论是在它自己的 div 中还是在标题中的特定 div 中,现在我可以上传里面的图片正文中的内容,但我不知道如何将其上传到标题中的徽标元素。

这是代码,所以你可以看到我希望它显示在哪里@model IEnumerable

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
  <script type="text/javascript" src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")

    </head>
<body>
    <header>
           <div id="float-logo"><img src="@Model.PicUrl" alt="" /></div>
           <div id="title"><p class="site-title">@Html.Action("SiteInfo", "Home")</p></div>
            <div class="float-login">
                <section id="login">
                    @Html.Partial("_LoginPartial")
                </section>
            </div>
                <nav id="MainNav">
                    <ul>
                        <li>@Html.ActionLink("Index", "Index", "Home")</li>
                        <li>@Html.ActionLink("Rapporter", "Index", "Report")</li>
                    </ul>
                </nav>
    </header>
    <div id="Layout">
        <nav id="SideNav"></nav>
        @RenderSection("featured", required: false)
        <section class="Content">
            @RenderBody()
        </section>
    </div>
    <footer></footer>

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>

这是创建它的控制器的一部分:

public class PictureController : Controller
{
    private ItbTidCmsEntities db = new ItbTidCmsEntities();

    //
    // GET: /Picture/

    public ActionResult Index()
    {
        var pictures = db.Pictures.Include("Category");
        return View(pictures.ToList());
    }
    public ActionResult Create(int? id)
    {

        ViewBag.CatID = id;
        var category = db.Categories.First(c => c.CatID == id.Value);
        ViewBag.CatName = category.CatName;

        return View();
    }

    //
    // POST: /Picture/Create

    [HttpPost]
    public ActionResult Create(Picture picture)
    {
        if (ModelState.IsValid)
        {
            db.Pictures.AddObject(picture);
            db.SaveChanges();
            return RedirectToAction("Content", "Admin", new { id = picture.CatID });
        }

        ViewBag.CatID = new SelectList(db.Categories, "CatID", "CatName", picture.CatID);
        return View(picture);
    }

管理模式:

namespace ItbTid.Models
{
    public class Admin
    {
        public List<Category> category { get; set; }
        public List<Text> text { get; set; }
        public List<Picture> picture { get; set; }
        public List<Video> video { get; set; }
        public List<Link> link { get; set; }
    }
}

时间条目列表模型:

namespace ItbTid.Models
{
  public class TimeEntryListModel
  {
    public IEnumerable<TimeEntry> TimeEntries { get; set; }
    public SelectList Customers { get; set; }
    public long? CustomerId { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
   }

  //Vi la till denna
  public class RegTimeModel
  {
      public TimeEntryListModel TimeEntryListModel { get; set; }
      public RegisterModel RegisterModel { get; set; }
      public IEnumerable<Customer> customerlist { get; set; }
  }
}

这是来自数据库 css_db.designer.cs 的一段代码:

public partial class Picture : EntityObject
{
    #region Factory Method

    /// <summary>
    /// Create a new Picture object.
    /// </summary>
    /// <param name="picID">Initial value of the PicID property.</param>
    /// <param name="picUrl">Initial value of the PicUrl property.</param>
    /// <param name="picAltText">Initial value of the PicAltText property.</param>
    public static Picture CreatePicture(global::System.Int64 picID, global::System.String picUrl, global::System.String picAltText)
    {
        Picture picture = new Picture();
        picture.PicID = picID;
        picture.PicUrl = picUrl;
        picture.PicAltText = picAltText;
        return picture;
    }

    #endregion
    #region Primitive Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int64 PicID
    {
        get
        {
            return _PicID;
        }
        set
        {
            if (_PicID != value)
            {
                OnPicIDChanging(value);
                ReportPropertyChanging("PicID");
                _PicID = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("PicID");
                OnPicIDChanged();
            }
        }
    }
    private global::System.Int64 _PicID;
    partial void OnPicIDChanging(global::System.Int64 value);
    partial void OnPicIDChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public global::System.String PicTitle
    {
        get
        {
            return _PicTitle;
        }
        set
        {
            OnPicTitleChanging(value);
            ReportPropertyChanging("PicTitle");
            _PicTitle = StructuralObject.SetValidValue(value, true);
            ReportPropertyChanged("PicTitle");
            OnPicTitleChanged();
        }
    }
    private global::System.String _PicTitle;
    partial void OnPicTitleChanging(global::System.String value);
    partial void OnPicTitleChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String PicUrl
    {
        get
        {
            return _PicUrl;
        }
        set
        {
            OnPicUrlChanging(value);
            ReportPropertyChanging("PicUrl");
            _PicUrl = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("PicUrl");
            OnPicUrlChanged();
        }
    }
    private global::System.String _PicUrl;
    partial void OnPicUrlChanging(global::System.String value);
    partial void OnPicUrlChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String PicAltText
    {
        get
        {
            return _PicAltText;
        }
        set
        {
            OnPicAltTextChanging(value);
            ReportPropertyChanging("PicAltText");
            _PicAltText = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("PicAltText");
            OnPicAltTextChanged();
        }
    }
    private global::System.String _PicAltText;
    partial void OnPicAltTextChanging(global::System.String value);
    partial void OnPicAltTextChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public global::System.String PicDesc
    {
        get
        {
            return _PicDesc;
        }
        set
        {
            OnPicDescChanging(value);
            ReportPropertyChanging("PicDesc");
            _PicDesc = StructuralObject.SetValidValue(value, true);
            ReportPropertyChanged("PicDesc");
            OnPicDescChanged();
        }
    }
    private global::System.String _PicDesc;
    partial void OnPicDescChanging(global::System.String value);
    partial void OnPicDescChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public Nullable<global::System.Int64> PicPrio
    {
        get
        {
            return _PicPrio;
        }
        set
        {
            OnPicPrioChanging(value);
            ReportPropertyChanging("PicPrio");
            _PicPrio = StructuralObject.SetValidValue(value);
            ReportPropertyChanged("PicPrio");
            OnPicPrioChanged();
        }
    }
    private Nullable<global::System.Int64> _PicPrio;
    partial void OnPicPrioChanging(Nullable<global::System.Int64> value);
    partial void OnPicPrioChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public Nullable<global::System.Int64> CatID
    {
        get
        {
            return _CatID;
        }
        set
        {
            OnCatIDChanging(value);
            ReportPropertyChanging("CatID");
            _CatID = StructuralObject.SetValidValue(value);
            ReportPropertyChanged("CatID");
            OnCatIDChanged();
        }
    }
    private Nullable<global::System.Int64> _CatID;
    partial void OnCatIDChanging(Nullable<global::System.Int64> value);
    partial void OnCatIDChanged();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public global::System.Byte[] PicDateCreated
    {
        get
        {
            return StructuralObject.GetValidValue(_PicDateCreated);
        }
        set
        {
            OnPicDateCreatedChanging(value);
            ReportPropertyChanging("PicDateCreated");
            _PicDateCreated = StructuralObject.SetValidValue(value, true);
            ReportPropertyChanged("PicDateCreated");
            OnPicDateCreatedChanged();
        }
    }
    private global::System.Byte[] _PicDateCreated;
    partial void OnPicDateCreatedChanging(global::System.Byte[] value);
    partial void OnPicDateCreatedChanged();

    #endregion

    #region Navigation Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [XmlIgnoreAttribute()]
    [SoapIgnoreAttribute()]
    [DataMemberAttribute()]
    [EdmRelationshipNavigationPropertyAttribute("ItbTidCmsModel", "FK_Pictures_Categories", "Categories")]
    public Category Category
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ItbTidCmsModel.FK_Pictures_Categories", "Categories").Value;
        }
        set
        {
            ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ItbTidCmsModel.FK_Pictures_Categories", "Categories").Value = value;
        }
    }
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [BrowsableAttribute(false)]
    [DataMemberAttribute()]
    public EntityReference<Category> CategoryReference
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Category>("ItbTidCmsModel.FK_Pictures_Categories", "Categories");
        }
        set
        {
            if ((value != null))
            {
                ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Category>("ItbTidCmsModel.FK_Pictures_Categories", "Categories", value);
            }
        }
    }

    #endregion
}
4

2 回答 2

0

我想你希望它显示在页面的左上角。只需将您的图像放入<div id="title">.

于 2013-05-03T12:46:53.470 回答
0

此动作需要返回图片URL

[HttpPost]
    public ActionResult Create(Picture picture)
    {
        if (ModelState.IsValid)
        {
            db.Pictures.AddObject(picture);
            db.SaveChanges();
            return RedirectToAction("Content", "Admin", new { id = picture.CatID });
        }

        ViewBag.CatID = new SelectList(db.Categories, "CatID", "CatName", picture.CatID);
        return View(picture);
//Return picture URL here
    }
于 2019-07-12T09:41:41.817 回答