C#MVC CMS简单生成 [英] C# MVC CMS simple generation

查看:73
本文介绍了C#MVC CMS简单生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设,我们有一个观点:ViewProduct.cshtml。现在假设我们要创建简单的AddProduct GET和POST操作。是否可以通过这样做自动生成AddProduct GET 版本:



完全呈现ViewProduct.cshtml中的内容,但替换每个@模型。$ ​​property $ of type string(如Model.Title,Model.Content,但不是Model.Date fe)@ Html.TextBoxFor(m => m。$ property)?我怎么能以以编程方式实现它?



概念是这样的:

public ProductController

{

public ActionResult ViewProduct(){...}

public ActionResult CMSViewProduct()

{

// PSEUDOCODE我寻找实现。

string html = GetHTMLCode(ViewProduct.cshtml);

html = html.Replace(@Model, ...)

返回查看(html); //这里的html包含每个@ Model的文本框。#property#其中property属于字符串类型。

}

}



我尝试了什么:



我已经构建了整个ViewProduct.cshtml并且我已准备好控制器。我特别仔细检查了Html.Render(RenderPartial,Partial),但它没有帮助,因为我需要先从ViewProduct.cshtml中获取整个代码,然后在将html发送给用户之前替换并添加文本框,以便如果我将来在Model和ViewProduct中添加新属性,CMS将立即准备好。

Let's assume, we have a view: "ViewProduct.cshtml". Now let's say we want to create simple AddProduct GET and POST actions. Is it possible to auto-generate AddProduct GET version by doing this:

Render exactly what is in ViewProduct.cshtml, but replace each @Model.$property$ of type string (like Model.Title, Model.Content, but not Model.Date f.e.) by @Html.TextBoxFor(m => m.$property)? How could I achieve it programmatically?

The concept is something like this:
public ProductController
{
public ActionResult ViewProduct() { ... }
public ActionResult CMSViewProduct()
{
// PSEUDOCODE I look for implementation of.
string html = GetHTMLCode("ViewProduct.cshtml");
html = html.Replace(@Model, ...)
return View(html); // here html would contain textboxes for each @Model.#property# where property is of string type.
}
}

What I have tried:

I have already built the whole ViewProduct.cshtml and I have controllers ready. I scrutinized Html.Render (RenderPartial, Partial) in particular, but it doesn't help, since I need something that would first take the whole code from ViewProduct.cshtml and then replace and add textboxs BEFORE sending html to user so that If I add new property inside Model and ViewProduct in the future, CMS will be immediately ready to go.

推荐答案

property


类型@ Html.TextBoxFor(m => m。
of type string (like Model.Title, Model.Content, but not Model.Date f.e.) by @Html.TextBoxFor(m => m.


属性)的字符串(如Model.Title,Model.Content,但不是Model.Date fe)?我怎么能以以编程方式实现它?



概念是这样的:

public ProductController

{

public ActionResult ViewProduct(){...}

public ActionResult CMSViewProduct()

{

// PSEUDOCODE我寻找实现。

string html = GetHTMLCode(ViewProduct.cshtml);

html = html.Replace(@Model, ...)

返回查看(html); //这里的html包含每个@ Model的文本框。#property#其中property属于字符串类型。

}

}



我尝试了什么:



我已经构建了整个ViewProduct.cshtml并且我已准备好控制器。我特别仔细检查了Html.Render(RenderPartial,Partial),但它没有帮助,因为我需要先从ViewProduct.cshtml中获取整个代码,然后在将html发送给用户之前替换并添加文本框,以便如果我将来在Model和ViewProduct中添加新属性,CMS将立即准备就绪。
property)? How could I achieve it programmatically?

The concept is something like this:
public ProductController
{
public ActionResult ViewProduct() { ... }
public ActionResult CMSViewProduct()
{
// PSEUDOCODE I look for implementation of.
string html = GetHTMLCode("ViewProduct.cshtml");
html = html.Replace(@Model, ...)
return View(html); // here html would contain textboxes for each @Model.#property# where property is of string type.
}
}

What I have tried:

I have already built the whole ViewProduct.cshtml and I have controllers ready. I scrutinized Html.Render (RenderPartial, Partial) in particular, but it doesn't help, since I need something that would first take the whole code from ViewProduct.cshtml and then replace and add textboxs BEFORE sending html to user so that If I add new property inside Model and ViewProduct in the future, CMS will be immediately ready to go.


这篇关于C#MVC CMS简单生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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