小编Her*_*rin的帖子

在MVC中使用Rotativa pdf显示动态标头

我想打印动态的标题数据,它将来自控制器.

那么如何使用Rotativa pdf在标题中显示动态数据.

我的标题数据包括名称,地址,联系信息和其他附加信息,这些信息是动态的,并从控制器端生成.

我使用html页面创建了带有静态头的pdf,如下所示

string header = Server.MapPath("~/Static/NewFolder/PrintHeader.html");
 string footer = Server.MapPath("~/Static/NewFolder/PrintFooter.html");

 string customSwitches = string.Format("--header-html  \"{0}\" " +
                        "--header-spacing \"0\" " +
                        "--footer-html \"{1}\" " +
                        "--footer-spacing \"10\" " +
                        "--footer-font-size \"10\" " +
                        "--header-font-size \"10\" ", header, footer);

return new ViewAsPdf("SchedulePrintPdf", modelData)
                    {
                        CustomSwitches = customSwitches,
                        PageOrientation = Orientation.Portrait,
                        PageMargins = { Top = 20, Bottom = 22 },
                        SaveOnServerPath = filePath, FileName = Path.GetFileName(fileName)
                    };
Run Code Online (Sandbox Code Playgroud)

这适用于Static标头.

现在我需要动态地从这个控制器发送标题文本.

pdf asp.net-mvc wkhtmltopdf rotativa

7
推荐指数
1
解决办法
8211
查看次数

基于从MVC中的应用程序选择语言的必填字段验证消息的本地化

我正在开发一个MVC4应用程序,因为在我的应用程序中有选择语言的选项,并根据所选的语言显示所有标签和消息。在此应用程序中,我对MVC进行了一个必填字段验证,它将显示验证我只在我的应用程序文件夹中为本地化创建了两个不同的xml文件,即用于英语lanaguage的Resource.resx和用于德语langauge的Resource.de-DE.resx。我在Model类中使用了以下代码:

    [Required(ErrorMessageResourceType = (typeof(MyFolder.MyResource.Resource)), ErrorMessageResourceName= "FromDateRequiredMessage")]
    [Display(Name = "FromDate", ResourceType = typeof(MyFolder.MyResource.Resource))]
    public DateTime FromDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

所以在这里我有Resource.resx xml文件,并且其中的键是'FromDateRequiredMessage',它与Resource.de-DE.resx德语文件中的键相同,但是值不同。此外,我在Web中进行了以下更改。全球化的配置文件:

<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto"/>
Run Code Online (Sandbox Code Playgroud)

因此,我希望当我从应用程序中选择德语时,它应该向我显示德语的验证错误。但是在这里,它将仅向我显示英语的验证消息。

那么,现在我该怎么办?请帮我。

globalization asp.net-mvc localization asp.net-mvc-validation asp.net-mvc-4

5
推荐指数
1
解决办法
4849
查看次数

使用邮递员接受 zip 文件

我已经在 .Net Core 应用程序中创建了 api 项目。我还创建了接受HttpRequestMessage作为参数的方法。现在我尝试使用Postman包含文件作为主体参数来调用我的 api 方法,但我的 api 方法没有调用。

这是代码

[Route("api/[controller]")]
public class ValuesController : Controller
{
    [HttpPost]
    public HttpResponseMessage PostFiles()
    {
        HttpResponseMessage result = null;
        var httpRequest = HttpContext.Request;

        return result;
    }}
Run Code Online (Sandbox Code Playgroud)

这是Postman请求数据

POST /api/values/PostFiles HTTP/1.1
Run Code Online (Sandbox Code Playgroud)

主机:localhost:64226 内容类型:multipart/form-data;边界=----WebKitFormBoundary7MA4YWxkTrZu0gW 缓存控制:无缓存邮递员令牌:6adcc652-a4ab-3714-cc5e-770bd214ac7a

------WebKitFormBoundary7MA4YWxkTrZu0gW 内容处置:表单数据;名称=“数据”;文件名=“”内容类型:

------WebKitFormBoundary7MA4YWxkTrZu0gW--

这是我使用 postman 进行 api 调用的屏幕截图。

在此输入图像描述

以文件作为参数的请求正文

在此输入图像描述

我有什么遗漏的吗?

您能帮我使用 Postman 调用我的 Web api 并接受文件作为参数吗?

postman .net-core asp.net-core-webapi

5
推荐指数
1
解决办法
9466
查看次数

使用带有MailKit的Html模板在.net核心应用程序中发送电子邮件

我正在使用MailKit从.net核心应用程序发送电子邮件,它将成功发送.

但我想使用HTML模板在.Net核心中使用MailKit发送电子邮件.

以下是当前使用静态正文部分发送电子邮件的代码

 var emailMessage = new MimeMessage();
        if (!string.IsNullOrWhiteSpace(cc))
        {
            emailMessage.Cc.Add(new MailboxAddress(cc));
        }
        else if (!string.IsNullOrWhiteSpace(EmailUserNameCC))
        {
            emailMessage.Cc.Add(new MailboxAddress(EmailUserNameCC));
        }
        if (!string.IsNullOrWhiteSpace(EmailUserNameBCC))
        {
            emailMessage.Bcc.Add(new MailboxAddress(EmailUserNameBCC));
        }

        emailMessage.From.Add(new MailboxAddress(mailFrom));
        emailMessage.To.Add(new MailboxAddress(mailTo));
        emailMessage.Subject = subject;
        if (!string.IsNullOrWhiteSpace(replyTo))
        {
            emailMessage.InReplyTo = replyTo;
        }
        var builder = new BodyBuilder();// { TextBody = message };
        builder.HtmlBody = message;

        if (attachments != null && attachments.Count > 0)
        {
            foreach (var item in attachments)
            {
                builder.Attachments.Add(item.Key, item.Value);
            }

            builder.HtmlBody = builder.HtmlBody + " \n" + " …
Run Code Online (Sandbox Code Playgroud)

c# email-templates asp.net-core-mvc mailkit asp.net-core-1.0

4
推荐指数
1
解决办法
5611
查看次数

自定义错误页面无法在实时服务器上运行

我在我的项目中实现了自定义错误功能,它在本地IIS上工作但不在实时服务器上工作.我已经使用Global.asax文件实现了这个功能,我在MVC中的自定义错误控制器中调用我的自定义错误操作方法.我已经发布并运行本地IIS及其工作,但在实时服务器上.

我的Global.asax.cs文件

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    //do not register HandleErrorAttribute. use classic error handling mode
    filters.Add(new HandleErrorAttribute());
}

protected void Application_Error(Object sender, EventArgs e)
{
    LogException(Server.GetLastError());

    CustomErrorsSection customErrorsSection = (CustomErrorsSection)ConfigurationManager.GetSection("system.web/customErrors");
    string defaultRedirect = customErrorsSection.DefaultRedirect;
    if (customErrorsSection.Mod e== CustomErrorsMode.On)
    {
        var ex = Server.GetLastError().GetBaseException();

        Server.ClearError();
        var routeData = new RouteData();
        routeData.Values.Add("controller", "Common");
        routeData.Values.Add("action", "CustomError");

        if (ex is HttpException)
        {
            var httpException = (HttpException)ex;
            var code = httpException.GetHttpCode();
            routeData.Values.Add("status", code);
        }
        else
        {
            routeData.Values.Add("status", 500);
        }

        routeData.Values.Add("error", ex);

        IController errorController …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc custom-errors global-asax

3
推荐指数
1
解决办法
2066
查看次数

ajax调用成功后重新加载页面会在safari和IE浏览器中出错

我使用了ajax调用来插入数据.并且在ajax调用的成功事件中,我想重新加载页面,所以我在ajax调用中编码为:

 myfunction: function (url, form) {

    $.ajax({
        cache: false,
        url: url,
        data: $(form).serialize(),
        type: 'post',
        success: window.location.reload(true),
        complete: this.resetLoadWaiting,
        error: "Failer Message."
    });
},
Run Code Online (Sandbox Code Playgroud)

这将适用于mozila firefox和google-crome,但不适用于所有版本的IE以及Safari浏览器,它将提供Failer Message,如ajax调用的错误部分.那么我在成功活动中能做些什么呢?

请帮我.

谢谢.

asp.net-mvc jquery asp.net-ajax

1
推荐指数
1
解决办法
5524
查看次数