Asp.net MVC /如何动态添加页面 [英] Asp.net MVC / how to add page dynamically

查看:420
本文介绍了Asp.net MVC /如何动态添加页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在asp.net mvc5中构建一个简单的cms,所以我完成了新闻部分,现在我正在使用PageConfig Controller,这是PageConfig类,管理面板中的SO或管理员角色我可以添加如何添加使用此页面模板动态页面,您能为我提供任何源代码/教程/帮助我该如何实现?!









命名空间

{

使用System;

使用System.Collections。 Generic;

使用System.ComponentModel.DataAnnotations;

使用System.Web.Mvc;



[Bind (排除=Id)]

公共部分类PageConfig

{



[ScaffoldColumn(false) ]

public int Id {get;组; }

public string PageId {get;组; }

public string Control {get;组; }

public string Content {get;组; }

公共字符串占位符{get;组; }

public Nullable< int> NrOfRecords {get;组; }

}

}









我会非常感谢任何帮助。



问候。



我尝试了什么:



I am building a simple cms in asp.net mvc5 , so i finished the News Part , Now i am working with PageConfig Controller , and this is the PageConfig Class, SO in the admin panel or by admin role HOW CAN i add a page dynamically with this page template , can you provide me any source code / tutorial / help how can i achieve that ?!




namespace
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

[Bind(Exclude = "Id")]
public partial class PageConfig
{

[ScaffoldColumn(false)]
public int Id { get; set; }
public string PageId { get; set; }
public string Control { get; set; }
public string Content { get; set; }
public string Placeholder { get; set; }
public Nullable<int> NrOfRecords { get; set; }
}
}




I would be very thankful for any help.

Regards.

What I have tried:

ASP.NET MVC / how to add page dynamically



i描述了上面的问题


i described the problem above

推荐答案

非没有控制器和视图(两者都被获得!)



之前需要在nuget控制台中安装Entityframework。



在web.config中设置DbContext(数据库存储库)和数据库连接。



右键单击在Project Properties中的Controller Folder,选择Add Controller=> Entityframework的空模板。



有两种方法可以做到这一点。



我建议你去获得了关于如何工作的详细知识。 MVC无法立即开始,没有从开始到结束的大本营知识。
Non without Controller and Views (Both is Acquired!)

Before you need to install Entityframework in nuget console.

Setup DbContext (Repository for Database) and Database conectionsTring in web.config.

Right-click Controller Folder in Project Properties, choose "Add Controller" => Empty Templates With Entityframework.

There are two ways to do this.

I recommended you go to acquired the knowledge in verbose on how to working. MVC cant start immediately without stronghold knowledge from starting stage to end.


如果你想从数据库获取内容,你只需要将字符串传递给View。



示例控制器





If you want to get content from database, you just have to pass string to the View.

Example Controller


Public ActionResult PageConfig()
{
   var html = .... /*Obtain content from database*/;
   return PartialView("PartialViewName",html);
}





示例视图



Example View

@model String

@Html.Raw(Model)





希望有所帮助。



Hope it helps.


这篇关于Asp.net MVC /如何动态添加页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆