问题标签 [razorengine]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
552 浏览

asp.net-mvc - 在 MVC4 中呈现 HTML 文件的正确方法是什么

我有一个带有布局的站点,并且正在尝试在视图中呈现一个普通的 Html 文件(可以每天更改)。

我之前做过部分视图,并想象解决方案会相似,但经过一些试验和(和搜索)我还没有找到一种方法来包含 html 文件,只是 cshtml。

0 投票
1 回答
4082 浏览

asp.net - 在 Razor View 中添加两个 ViewData 变量

我是 ASP 新手。我想知道我可以在控制器的变量传递视图中添加两个ViewData变量吗?RazorASP.net MVC4

0 投票
1 回答
410 浏览

c# - 无法访问列表上的 Take() with System.Linq referenced in using

I am using RazorEngine for email templating. I have introduced Take() method into the template. I did this so the authors can dictate how many records they want without us havi

I am using RazorEngine for email templating. I have introduced Take() method into the template. I did this so the authors can dictate how many records they want without us having to change any C# in our code directly. I have tried adding the using statements to the template itself as well as using the fluent configuration and adding the namespaces needed but I am not having any luck.

Error:

Here is my fluent configuration for RazorEngine:

If I purposely state a namespace incorrectly, I do get an error saying it couldn't find it so I know that it is processing the config data but despite that, I am still getting the error.

Any ideas on what I am doing wrong? I am passing in a dynamic model which either is a List or has a List on it.


send json request using php for and api

I am working on some api in which I send information using json.

POST /api/v3/users/ HTTP/1.1

Host: example.com

Content-Type: application/vnd.api+json

Authorization: Bearer ab1dcb45be7e43db2212b0d2b0ca3892

This is the information. Using this will get that response but I don't know how to use this in php and not use js?

get response:

But I don't know how to use this, meaning how to send request.

0 投票
1 回答
731 浏览

asp.net-mvc-3 - 如何从 Viewbag mvc4 中显示数据?

这是我的控制器

我想在表格的视图中显示数据,在一个视图中显示 2 个 db 模型时出现问题,因为从数据库生成的模型不是 Code First 所以我尝试使用 ViewData 显示数据有什么帮助吗?

0 投票
1 回答
3266 浏览

c# - 如何在管理 MVC 4 应用程序中重用模型和视图以进行添加和编辑

我正在使用 C# 构建 MVC 4 应用程序,并且我一直在做很多彼此非常相似的添加和编辑视图。我的问题是如何通过填写表单以添加和编辑项目来重用与模型返回的对象的相同视图。这是我在我的应用程序中执行的示例:

和我的添加方法:

当我编辑时,我需要打开与 AddUser 相同的视图,但在模型中填充适当的属性并发布以保存模型中的更改。目前我使用 ViewData["Username"] ,||-|| “密码”,所以要做到这一点,有没有更好的方法来重用这个 AddUser 视图?

寄存器模型如下

0 投票
1 回答
876 浏览

.net - 剃刀引擎中的西里尔字符问题

请帮助,我的 asp.net-mvc 应用程序的电子邮件通知中的西里尔字符有问题,它在 Outlook 中显示不正确。我使用 SmtpClient 发送消息,使用 razor 引擎创建消息(我有一些用于不同类型消息的模板)。我已经为我的模板添加了带有 charset utf-8 的元标记,还添加了

对于我的消息对象(MailMessage 类的实例),但问题仍然存在。在 web 界面消息看起来很好,这个问题只出现在 Outlook 中。
谢谢!

0 投票
2 回答
1110 浏览

asp.net-mvc - RazorEngine - @Html.LabelFor OK,@Html.EditorFor 在 Execute() 上“未实现异常”

我目前正在评估 RazorEngine 以查看它是否可以在我们的项目中使用 - 我们需要动态重新排序视图中的字段,因此我正在尝试向 RazorEngine 发送一个字符串以获取完整的 HTML 并将其显示给用户。

我已经将 RazorEngine 与 @Html.LabelFor() 一起使用,它工作正常。我在这篇 SO 帖子中使用了 mao47 的代码: https ://stackoverflow.com/a/19434112/2878135 ,它基于 Abu Haider 的代码: http ://www.haiders.net/post/HtmlTemplateBase.aspx

但这不适用于 @Html.EditorFor() 。我抛出 System.NotImplementedException - 方法或操作未实现。这是来自一个新的 MVC4 项目。除了实现来自 mao47 的代码外,没有进行任何代码更改。

我有 RazorEngine 源代码,在调用 Execute() 时出现错误

堆栈跟踪如下所示:

0 投票
1 回答
2413 浏览

asp.net-mvc - 在控制器操作中调用 RazorEngine.Parse() 失败,HttpContextBase 错误

也许我没有在正确的地方调用 RazorEngine。

在我的控制器操作中,我使用以下代码调用 RazorEngine。但我认为这可能不正确,因为当它调用 .Execute() 然后调用 MVC 的 GetActionCache() 时,HttpContextBase.Items 失败并出现“方法未实现”异常。

我是否以错误的方式调用 RazorEngine?@Html.LabelFor() 工作正常。

0 投票
1 回答
10905 浏览

c# - 如何让 RazorEngine Parse 方法与布局一起成功工作?

我正在使用RazorEngine,如果我在视图中指定布局,Parse 方法会引发错误。如果我没有指定它,则 Parse 成功但布局不存在(如果在 _ViewStart.cshtml 中指定,它似乎忽略了布局)。请建议告诉我如何让 RazorEngine Parse 方法与布局一起成功工作?

我在下面包含了 C#、视图和布局:

看法

布局

错误是:对象引用未设置为对象的实例。

没有内部错误,但堆栈跟踪显示:

0 投票
0 回答
168 浏览

asp.net-mvc-4 - Html.Partial string combine for view file name

Why is this not working:

My partial view file names: Training11.cshtml, Training12.cshtml, etc And is there a solution for this? Otherwise I need to create 8 * 8 if(/switch) statements..