I'm working on Visual Studio Web based MVC and I am using Rotativa to display PDF as output view/download.
right now I am able to design and display a whole page with content and footer. the Footer appears on every page.
My problem is, I am instructed to print only Footer on first page only and the rest of the page must have no footer.
I kept on searching "Rotativa Footer on First Page Only" and similar keywords, but i cant find any solution to this.
I use this custom switch that generates footer from other controller/action that has HTML design for footer.
string CustomSwitch = $"--footer-font-size \"8\" --footer-html \" {Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + Url.Content("~/FooterHTML/index/?Id=" + footerId )} \"";
var rotativaOptions = new DriverOptions()
{
PageSize = Size.A4,
PageOrientation = Orientation.Portrait,
PageMargins = new Margins(24, 0, 27, 0),
CustomSwitches = CustomSwitch
};
return new ViewAsPdf("PDFwithFooter", model)
{
RotativaOptions = rotativaOptions
};
This are the namespace I use.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Rotativa;
using Rotativa.MVC;
using Rotativa.Core;
using Rotativa.Core.Options;
using PDF_Project.Models;
Related
Hi I created my classlib and added my viewcomponents to that library and I added DLL file of my class library to asp.net mvc application I can able to use class and models but I don't know how to render cshtml page from library
this is my library
enter image description here
this is how I configred it now
enter image description here
this is how I call
enter image description here
Add the problem is
enter image description here
I want to know how to configure cshtml page from classlib I use this as reference
https://www.davepaquette.com/archive/2016/07/16/loading-view-components-from-a-class-library-in-asp-net-core.aspx
My Code
https://github.com/Mohammedyasith/ViewComponent
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio#enable-runtime-compilation-conditionally
Follow This Link to configer
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Intelizign.Net.ViewComponents.NavBarViewComponent;
using Microsoft.Extensions.FileProviders;
var builder = WebApplication.CreateBuilder(args);
var env = builder.Environment;
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
var mvcBuilder = builder.Services.AddRazorPages();
if (builder.Environment.IsDevelopment())
{
mvcBuilder.AddRazorRuntimeCompilation();
}
builder.Services.AddControllersWithViews();
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(o =>
{
var libraryPath = Path.GetFullPath(
Path.Combine(builder.Environment.ContentRootPath, "..", "vLib"));
o.FileProviders.Add(new PhysicalFileProvider(libraryPath));
});
I have developed web app using ReactJS when i navigate one page to another page the header text should be changed based url (i created header component and i did import in all pages) how to achieve this
if you are using client-side use javascript to handle it:
componentDidUpdate(){
var path= window.location.pathname; // lets imaging that url is "/home/x"
var pathArray = path.split( '/' );
var loc= pathArray[2];//number of part of url that is changing, here it rerurns x
if(loc === "product"){ // if x be "product" it returns true
//do somting
}
}
if using server-side rendering instead of using "var path= window.location.pathname;" it's better to save URL path in store and use it in your component.
I am working on an umbraco project, which has been a very steep learning curve, there doesn't seem to be to much good documentation around for v7 and mvc in particular.
I have built out a simple list of items with pagination and ordering using ling with query strings. Not particularly nice. I want to work out a way of making all of this clientside and what the options are and best practices are within umbraco.
Any help gratefully appreciated.
Thanks in advance
Richard
There are many ways to do this, here is a simple one. In summary, I reccomend using a "Surface Controller" called by ajax and then manipulate your DOM accordingly.
Here is a sample Surface Controller (I have a bunch of useless usings there...):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Net;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Configuration;
using System.IO;
using Newtonsoft.Json;
using System.Text;
using Umbraco.Web; // AncestorOrSelf
using Umbraco.Core; // FindIndex
using Umbraco.Core.Models;
namespace MyFunWebsite.SurfaceControllers
{
public class MyFunSCController : Umbraco.Web.Mvc.SurfaceController
{
[System.Web.Mvc.HttpPost]
public ActionResult GetPage() {
// Pick up params
var pageNumber = -1;
if (!int.TryParse(Request.Params["pageNumber"], out pageNumber))
{
pageNumber = -1;
}
var parentNodeId = -1;
if (!int.TryParse(Request.Params["parentNodeId"], out parentNodeId))
{
parentNodeId = -1;
}
if (parentNodeId == -1 || pageNumber == -1)
{
return Content("no - invalid parentNodeId or pageNumber");
}
var itemsPerPage = 10;
var parentNode = Umbraco.TypedContent(parentNodeId);
var nodes = parentNode.Children.Skip(itemsPerPage * pageNumber).Take(itemsPerPage);
ViewBag.specialViewBagInformation = "Fun with Umbraco";
ViewBag.nodes = nodes;
return PartialView("Partials/MyListingOfNodes");
}
}
}
Then that partial view goes like this:
#using Umbraco.Core;
#{
var nodes = (IEnumerable<IPublishedContent>)ViewBag.nodes;
foreach (var node in nodes) {
<div>title: #node.AsDynamic().title</div>
}
}
Now your normal template, the one seem to already have can also call this partial. That template has to display page buttons also based on counts and items per page and stuff. But then basically, when a page button runs, you run some javascript similar to this:
function GetPage(pageNumber, parendNodeId) {
$.ajax({
type: "POST",
url: "/Umbraco/Surface/MyFunSCController/GetPage/",
data: "pageNumber=" + pageNumber + "&parentNodeId=" + parentNodeId,
cache: false,
dataType: "text",
success: function (result) {
$("#myFunTable").html(result);
},
error: function (result) {
// console.log("Ajax error: " + result);
}
});
}
Notice the url for the ajax post "/Umbraco/Surface/", controllers you create that extend "Umbraco.Web.Mvc.SurfaceController" will be accessible there. Very convinient for ajax calls. This javascript will prevent your page from requiring to reload, keeping things clientside but still using the serverside to get the content you want. From here you can add a lot of functionnality and validations.
Here is a page button:
Page 3
Hope this helps you work with Umbraco, I think it's a very powerful product.
I am currently working on a kendo ui tab. It contains tab1,tab2,tab3.
The first tab has the kendo ui grid which worked fine. What I am trying to do is when a user selects a record on tab 1, tab 2 , or tab 3 it will be enabled with data populated from controller.
here is the code:
function onChange() {
var grid = $("#product").data("kendoGrid"); ;
var selected = grid.select();
if (selected.length) {
var data = grid.dataItem(selected);
var trn= data.TRN;
$($('#tabstrip').find('a.k-link')[3]).data('contentUrl', 'TestPlan?TRN=' + hrn);
$($('#tabstrip').find('a.k-link')[2]).data('contentUrl', 'Summary?TRN=' + hrn);
var ts = $('#tabstrip').data("kendoTabStrip");
ts.reload(ts.tabGroup.children("li")[3]);
ts.reload(ts.tabGroup.children("li")[2]);
ts.enable(ts.tabGroup.children("li")[3]);
ts.enable(ts.tabGroup.children("li")[2]);
}
}
Testing:
If I use Chrome to inspect the error that they could not find the link of tab 2 and tab 3
So I suspect that my url content not format properly because it works in the local environment but not in the server
So how I could modify the following link using URL.content?
$($('#tabstrip').find('a.k-link')[3]).data('contentUrl', 'TestPlan?TRN=' + trn);
$($('#tabstrip').find('a.k-link')[2]).data('contentUrl', 'Summary?TRN=' + trn);
try to use this syntax : '/TestPlan?TRN='
i found it:
$($('#tabstrip').find('a.k-link')[1]).data('contentUrl', '#(Url.Content("~/TestPlan?TRN="))' + trn);
When I email myself sample mhtml files (e.g. from here) images display fine in Outlook. However, when I convert a Word document to mht (Web Archive) format, the images do not display. If I open the file in a browser, the images display fine, or if I attach the mht file and double click on the attachment. But if the file is inlined in the email, then I get the red X box with 'Right click here to download pictures', and if I select download pictures, then 'file can not be displayed...may have moved...'.
Any ideas why images in Word docs converted to MHTML do not like to display inline in emails?
An MHTML document is a multi-part MIME document. The first part of the document is HTML and has links to the images in the other parts. The problem is that the links don't work in an inline email even though they do work in a browser. Looking at some examples, you can see the links must be prefixed by "cid:", and the part after the "cid:" must have a Content-ID in the header of the corresponding MIME part.
The link can be as simple as "cid:image002.gif" with the Content-ID in the corresponding MIME part being:
Content-ID: <image002.gif>
If all of the links are fixed in this way, the html with the images will display inline in Outlook.
As mentioned above, you use the Content ID to link attachments to image tags within the HTML body of your email. Below is a full program for opening an MHT file, adjusting the links, and emailing the results.
I have a client that is using the Word Automation Service to convert incoming emails to MHT files and emailing them. The issue is that Outlook didn't care much for the raw MHT and didn't inline the images. Here is my POC for a solution. I utilized the MimeKit and MailKit (http://www.mimekit.net/) in the code, the Bouncy Castle C# API (http://www.bouncycastle.org/csharp/) to cover a dependency within the MailKit, and Antix SMTP Server for Developers (http://antix.co.uk/Projects/SMTP-Server-For-Developers) running on the local server to receive the SMTP traffic for testing the code in dev. Below is the POC code that opens an existing MHT file and emails it with embedded images.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using MimeKit;
using MailKit;
using MimeKit.Utils;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
MimeMessage messageMimeKit = MimeMessage.Load(#"c:\test.mht");
var images = messageMimeKit.BodyParts.Where(x => x.ContentLocation.LocalPath.EndsWith("png"));
var bodyString = messageMimeKit.HtmlBody;
var builder = new BodyBuilder();
foreach (var item in images)
{
item.ContentId = MimeUtils.GenerateMessageId();
bodyString = bodyString.Replace(GetImageName(item), "cid:" + item.ContentId.ToString());
builder.LinkedResources.Add(item);
}
builder.HtmlBody = bodyString;
messageMimeKit.Body = builder.ToMessageBody();
messageMimeKit.From.Add(new MailboxAddress("from address", "NoReply_SharePoint2013Dev#smithmier.com"));
messageMimeKit.To.Add(new MailboxAddress("to address", "larry#smithmier.com"));
messageMimeKit.Subject = "Another subject line";
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("localhost");
client.Send(messageMimeKit);
client.Disconnect(true);
}
}
private static string GetImageName(MimeEntity item)
{
return item.ContentLocation.Segments[item.ContentLocation.Segments.Count() - 2] +
item.ContentLocation.Segments[item.ContentLocation.Segments.Count() - 1];
}
}
}