Posts

Showing posts with the label Razor

Binding a Dropdownlist on a blank form to a Model using a dictionary

In my Models folder I have a class for United States that looks like this:  public class UnitedStates     {           public static readonly IDictionary Cust_States = new Dictionary<string, object>                 {{"AL", "AL"},{"AK", "AK"},{"AZ", "AZ"},{"AR", "AR"},{"CA", "CA"},{"CO", "CO"},                 {"CT", "CT"},{"DE", "DE"},{"FL", "FL"},{"GA", "GA"},{"HI", "HI"},{"ID", "ID"},                 {"IL", "IL"},{"IN", "IN"},{"IA", "IA"},{"KS", "KS"},{"KY", "KY"},{"LA", "LA"},                 {"ME", "ME"},{"MD", "MD"},{"MA", "MA"},{"MI", "MI...

Simple Breadcrumbs in Razor

If you wish to add Breadcrumb navigation to your site. This is a quick and easy way to do it.  This is only effective if every controller has an Index view and if you are passing route variables such as 'acct=xxx' then this will not accommodate those values so you have to make sure your app is able to manage without the variables and offer another option. @Html.ActionLink("Home", "Index", "Home") @if(ViewContext.RouteData.Values["controller"].ToString() != "Home") { @Html.ActionLink(ViewContext.RouteData.Values["controller"].ToString(), "Index", ViewContext.RouteData.Values["controller"].ToString()) } @if(ViewContext.RouteData.Values["action"].ToString() != "Index"){     @Html.ActionLink(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString()...

PDF from MVC Razor - with heading

Image
Today I was tasked with creating a PDF from a report that had two queries - a header section and detail section. After looking at all the viable options I was tempted by iTextSharp but was faced with the challenge of implementing it in razor.  I then came across this nifty dll written specifically for that purpose and it utilizes iTextSharp to do it. RazorPDF  was the answer.  Al Nyveldt did an excellent job with it and includes a github download with great samples.  The one challenge he didn't cover was my example of two queries to make a more comprehensive report. As shown in the example (screenshot of my pdf generated using this tool) I have header information as well as additional data laid out in a table. To accomplish this I created a ViewModel in my Data project with a simple class that incorporated two references.  One to the header data and one to the Zipcode detail.     public class Fran_Zip_ViewModel     {   ...