Posts Tagged ‘html’

Rotativa

Extremely easy way to create Pdf files from Asp.net MVC.

Usage:

public ActionResult PrintIndex()
{
    return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
}
public ActionResult Index(string name) 
{ 
    ViewBag.Message = string.Format("Hello {0} to ASP.NET MVC!", name); 
    return View(); 
}

ViewAsPdf now available. It enables you to render a view as pdf in just one move, thanks to scoorf

public ActionResult TestViewWithModel(string id)
{
    var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
    return new ViewAsPdf(model);
}

Also available a RouteAsPdf, UrlAsPdf and ViewAsPdf ActionResult.

It generates Pdf also from authorized actions (web forms authentication).

 

Documentation:

Advertisements

Gets the attachment collection used to store alternate forms of the message body.

 

Use the AlternateViews property to specify copies of an e-mail message in different formats. For example, if you send a message in HTML, you might also want to provide a plain text version in case some of the recipients use e-mail readers that cannot display HTML content.

To add an alternate view to a MailMessage object, create an Attachment for the view, and then add it to the collection returned by AlternateViews. Use the Body property to specify the text version and use the AlternateViews collection to specify views with other MIME types. Use the MediaTypeNames class members to specify the MIME type for the alternate view.

The following code example demonstrates creating and sending an e-mail message with a plain text and an HTML alternate view.


		public static void CreateMessageWithMultipleViews(string server, string recipients)
		{
			// Create a message and set up the recipients.
			MailMessage message = new MailMessage(
				"jane@contoso.com",
				recipients,
				"This e-mail message has multiple views.",
				"This is some plain text.");

			// Construct the alternate body as HTML.
			string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
			body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
			body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text";
			body += "</FONT></DIV></BODY></HTML>";

			ContentType mimeType = new System.Net.Mime.ContentType("text/html");
			// Add the alternate body to the message.

			AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, mimeType);
			message.AlternateViews.Add(alternate);

			// Send the message.
			SmtpClient client = new SmtpClient(server);
			client.Credentials = CredentialCache.DefaultNetworkCredentials;

      try {
			  client.Send(message);
			}
			catch (Exception ex) {
			  Console.WriteLine("Exception caught in CreateMessageWithMultipleViews(): {0}",
                    ex.ToString() );
      }
			// Display the values in the ContentType for the attachment.
			ContentType c = alternate.ContentType;
			Console.WriteLine("Content type");
			Console.WriteLine(c.ToString());
			Console.WriteLine("Boundary {0}", c.Boundary);
			Console.WriteLine("CharSet {0}", c.CharSet);
			Console.WriteLine("MediaType {0}", c.MediaType);
			Console.WriteLine("Name {0}", c.Name);
			Console.WriteLine("Parameters: {0}", c.Parameters.Count);
			foreach (DictionaryEntry d in c.Parameters)
			{
				Console.WriteLine("{0} = {1}", d.Key, d.Value);
			}
			Console.WriteLine();
			alternate.Dispose();
		}

 

Source: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews.aspx

The problem is that your anonymous object property data-icon has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that:

Use an underscore instead of dash (MVC will automatically replace the underscore with a dash in the emitted HTML):

@Html.ActionLink("Edit","edit","markets",new{ id =1},new{@class="ui-btn-right", data_icon="gear"})
 

Use the overload that takes in a dictionary:

@Html.ActionLink("Edit", "edit", "markets",
      new { id = 1 },
      new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });

source: http://stackoverflow.com/questions/4108943/actionlink-htmlattributes