如何使用实体框架在 ASP MVC 3 Razor 视图中添加图像作为详细信息
对于正在进行的项目,我(以及其他类)具有以下内容:
public class Page
{
[Key]
public int PageId { get; set; }
public string Name { get; set; } //eg. "AboutUs", "Location"
[Column(TypeName = "ntext")] //force Entity Framework to create a ntext column
public string Title { get; set; }
public string Subtitle { get; set; }
public string Content { get; set; }
//navigational properties
public virtual ObservableCollection<Image> Images{ get; set; } //one Page has many Images
public Page()
{
Images= new ObservableCollection<Image>();
}
}
我在此 ASP MVC 3 项目中使用实体框架代码优先方法(使用 Razor),并且在插入和更新此类型的对象时没有任何问题。
但是:我怎样才能拥有一个主细节视图,其中细节部分仅由图像组成(请参阅类定义)。 那么,如果用户不希望删除图像,如何添加图像,当然如何显示列表中的所有图像呢?
任何提示都深表感谢!
For an ongoing project i have (amongst other classes) the following:
public class Page
{
[Key]
public int PageId { get; set; }
public string Name { get; set; } //eg. "AboutUs", "Location"
[Column(TypeName = "ntext")] //force Entity Framework to create a ntext column
public string Title { get; set; }
public string Subtitle { get; set; }
public string Content { get; set; }
//navigational properties
public virtual ObservableCollection<Image> Images{ get; set; } //one Page has many Images
public Page()
{
Images= new ObservableCollection<Image>();
}
}
I'm using Entity Framework code first approach in this ASP MVC 3 project (using Razor) and do not have any problem inserting and updating objects of this type.
BUT: how can i have a master detail view in which the detail part is composed by images only (see class definition).
So how is it possible to add an image, if the user doesn't want it to have it deleted and of course how to show all the images in a list?
Any hint is deeply appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看这篇文章:在 asp mvc 中显示数据库中的图像
如果您尝试从数据库渲染,在控制器中创建一个方法来获取图像并将其用作图像源,如上面的示例所示。唯一的区别是你的模型将包含在 a 中,
然后你的模型将包含图像的 Id,并且操作方法的工作就是检索图像。
Look at this post: Display image from database in asp mvc
If you are trying to render from the database, create a method in your controller to get the image and use that as your image source like in the example above. The only difference is yours will be contained in a
Then your model would contain the Id's of the images, and it would be the job of the action method to retrieve the image.