I had reviewed lots of questions already posted on StackOverFlow and most of the answers ended up on what CMS platform to use instead of how to actually create one from Scratch.
Searching the Internet and Books also did not result in any useful answers to my questions.
I am fairly new to using Asp.Net MVC and wanted to know how to make a very basic CMS with Asp.Net, MVC, Entity Framework, in C#.
My main issue is creating database driven pages that are not hard coded into the MVC Controller and not physically located as Somepage.cshtml
Would like to know how to do the following:
Incoming URL: MainWebsite.com/DatabaseProvidedPage
Goal is for the controller in Route for pages without a /controller/ in the URL to default as being a Database Driven/Created Webpage.
Would like to actually know how to do this.
Not looking for a platform to use to do this.
I want to learn the basics of creating a CMS using Asp.Net MVC.
Just really want:
How to do this?
URL: MainWebsite/DatabaseProvidedWebpage --> Return to user the HTML stored in database
Thanks,
Found Solution:
// Display Database Provided Page MainSite.Com/{PageName}
routes.MapRoute("DatabasePage",
"{PageName}",
new { controller = "Home",
action = "Index",
PageName = ""
});
public ActionResult Index(String PageName)
{
if (PageName == null)
{
List<PageTable> pages = PagesRepository.GetAllPages();
return View(pages);
}
PageTable FindPageName = PagesRepository.GetPageByURL(PageName);
if (FindPageName == null)
{
return Content(PageName);
}
if (FindPageName != null)
{
return View(FindPageName);
}
return View("");
}
@model CMS_Repository.DAL.EF.PageTable
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>PageTable</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Content)
</dt>
<dd>
@Html.DisplayFor(model => model.Content)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FriendlyURL)
</dt>
<dd>
@Html.DisplayFor(model => model.FriendlyURL)
</dd>
<dt>
@Html.DisplayNameFor(model => model.ControllerName)
</dt>
</dl>
Scaffolding does this automatically for you, only not with Guids. When you scaffold, you get a controller with several actions, one of which is Details. By accessing /Controller/Details/[id] you see details about the specified item. Create a table with a column for your HTML; let's call it HTML. In the Details view, write
@Html.Raw(Model.HTML)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With