C#MVC CMS简单生成

编程入门 行业动态 更新时间:2024-10-11 19:25:52
本文介绍了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简单生成

本文发布于:2023-10-12 04:05:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   MVC   CMS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!