Browse files

Merge pull request #3 from fredrikn/master

Added some few features, like error page, start page.. made some few fixes..
  • Loading branch information...
2 parents 223a669 + 5508337 commit 64c23824ea420149e660ae4597cc0b790b5fb11e @panesofglass panesofglass committed Aug 29, 2012
View
9 samples/MvcWebApiSiteTest/App_Start/WebApiConfig.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web.Http;
+using System.Web.Http;
namespace MvcWebApiSiteTest
{
@@ -11,8 +8,8 @@ public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { id = RouteParameter.Optional }
+ routeTemplate: "{controller}/{id}",
+ defaults: new { controller = "Home", id = RouteParameter.Optional }
);
}
}
View
940 samples/MvcWebApiSiteTest/Content/Site.css
@@ -1,756 +1,432 @@
-html {
- background-color: #e2e2e2;
- margin: 0;
- padding: 0;
-}
+
+/*******************************************************************************
+Slate Theme for Github Pages
+by Jason Costello, @jsncostello
+*******************************************************************************/
-body {
- background-color: #fff;
- border-top: solid 10px #000;
- color: #333;
- font-size: .85em;
- font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;
- margin: 0;
- padding: 0;
-}
+@import url(pygment_trac.css);
-a {
- color: #333;
- outline: none;
- padding-left: 3px;
- padding-right: 3px;
- text-decoration: underline;
-}
+/*******************************************************************************
+MeyerWeb Reset
+*******************************************************************************/
- a:link, a:visited,
- a:active, a:hover {
- color: #333;
- }
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, canvas, details, embed,
+figure, figcaption, footer, header, hgroup,
+menu, nav, output, ruby, section, summary,
+time, mark, audio, video {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font: inherit;
+ vertical-align: baseline;
+}
- a:hover {
- background-color: #c7d1d6;
- }
+/* HTML5 display-role reset for older browsers */
+article, aside, details, figcaption, figure,
+footer, header, hgroup, menu, nav, section {
+ display: block;
+}
-header, footer, hgroup,
-nav, section {
- display: block;
+ol, ul {
+ list-style: none;
}
-mark {
- background-color: #a6dbed;
- padding-left: 5px;
- padding-right: 5px;
+blockquote, q {
}
-.float-left {
- float: left;
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
}
-.float-right {
- float: right;
+a:focus {
+ outline: none;
}
-.clear-fix:after {
- content: ".";
- clear: both;
- display: block;
- height: 0;
- visibility: hidden;
+/*******************************************************************************
+Theme Styles
+*******************************************************************************/
+
+body {
+ box-sizing: border-box;
+ color:#373737;
+ background: #212121;
+ font-size: 16px;
+ font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
+ line-height: 1.5;
+ -webkit-font-smoothing: antialiased;
}
-h1, h2, h3,
-h4, h5, h6 {
- color: #000;
- margin-bottom: 0;
- padding-bottom: 0;
+h1, h2, h3, h4, h5, h6 {
+ margin: 10px 0;
+ font-weight: 700;
+ color:#222222;
+ font-family: 'Lucida Grande', 'Calibri', Helvetica, Arial, sans-serif;
+ letter-spacing: -1px;
}
h1 {
- font-size: 2em;
+ font-size: 36px;
+ font-weight: 700;
}
h2 {
- font-size: 1.75em;
+ padding-bottom: 10px;
+ font-size: 32px;
+ background: url('../images/bg_hr.png') repeat-x bottom;
}
h3 {
- font-size: 1.2em;
+ font-size: 24px;
}
h4 {
- font-size: 1.1em;
+ font-size: 21px;
}
-h5, h6 {
- font-size: 1em;
+h5 {
+ font-size: 18px;
}
- h5 a:link, h5 a:visited, h5 a:active {
- padding: 0;
- text-decoration: none;
- }
-
-
-/* main layout
-----------------------------------------------------------*/
-.content-wrapper {
- margin: 0 auto;
- max-width: 960px;
+h6 {
+ font-size: 16px;
}
-#body {
- background-color: #efeeef;
- clear: both;
- padding-bottom: 35px;
+p {
+ margin: 10px 0 15px 0;
}
- .main-content {
- background: url("../Images/accent.png") no-repeat;
- padding-left: 10px;
- padding-top: 30px;
- }
+footer p {
+ color: #f2f2f2;
+}
- .featured + .main-content {
- background: url("../Images/heroAccent.png") no-repeat;
- }
+a {
+ text-decoration: none;
+ color: #007edf;
+ text-shadow: none;
-header .content-wrapper {
- padding-top: 20px;
+ transition: color 0.5s ease;
+ transition: text-shadow 0.5s ease;
+ -webkit-transition: color 0.5s ease;
+ -webkit-transition: text-shadow 0.5s ease;
+ -moz-transition: color 0.5s ease;
+ -moz-transition: text-shadow 0.5s ease;
+ -o-transition: color 0.5s ease;
+ -o-transition: text-shadow 0.5s ease;
+ -ms-transition: color 0.5s ease;
+ -ms-transition: text-shadow 0.5s ease;
}
-footer {
- clear: both;
- background-color: #e2e2e2;
- font-size: .8em;
- height: 100px;
+#main_content a:hover {
+ color: #0069ba;
+ text-shadow: #0090ff 0px 0px 2px;
}
+footer a:hover {
+ color: #43adff;
+ text-shadow: #0090ff 0px 0px 2px;
+}
-/* site title
-----------------------------------------------------------*/
-.site-title {
- color: #c8c8c8;
- font-family: Rockwell, Consolas, "Courier New", Courier, monospace;
- font-size: 2.3em;
- margin: 0;
+em {
+ font-style: italic;
}
-.site-title a, .site-title a:hover, .site-title a:active {
- background: none;
- color: #c8c8c8;
- outline: none;
- text-decoration: none;
+strong {
+ font-weight: bold;
}
+img {
+ position: relative;
+ margin: 0 auto;
+ max-width: 739px;
+ padding: 5px;
+ margin: 10px 0 10px 0;
+ border: 1px solid #ebebeb;
-/* login
-----------------------------------------------------------*/
-#login {
- display: block;
- font-size: .85em;
- margin: 0 0 10px;
- text-align: right;
+ box-shadow: 0 0 5px #ebebeb;
+ -webkit-box-shadow: 0 0 5px #ebebeb;
+ -moz-box-shadow: 0 0 5px #ebebeb;
+ -o-box-shadow: 0 0 5px #ebebeb;
+ -ms-box-shadow: 0 0 5px #ebebeb;
}
- #login a {
- background-color: #d3dce0;
- margin-left: 10px;
- margin-right: 3px;
- padding: 2px 3px;
- text-decoration: none;
- }
+pre, code {
+ width: 100%;
+ color: #222;
+ background-color: #fff;
- #login a.username {
- background: none;
- margin: 0;
- padding: 0;
- text-decoration: underline;
- }
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
+ font-size: 14px;
- #login ul {
- margin: 0;
- }
+ border-radius: 2px;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
- #login li {
- display: inline;
- list-style: none;
- }
-/* menu
-----------------------------------------------------------*/
-ul#menu {
- font-size: 1.3em;
- font-weight: 600;
- margin: 0 0 5px;
- padding: 0;
- text-align: right;
}
- ul#menu li {
- display: inline;
- list-style: none;
- padding-left: 15px;
- }
-
- ul#menu li a {
- background: none;
- color: #999;
- text-decoration: none;
- }
-
- ul#menu li a:hover {
- color: #333;
- text-decoration: none;
- }
-
-
-/* page elements
-----------------------------------------------------------*/
-/* featured */
-.featured {
- background-color: #fff;
+pre {
+ width: 100%;
+ padding: 10px;
+ box-shadow: 0 0 10px rgba(0,0,0,.1);
+ overflow: auto;
}
- .featured .content-wrapper {
- background-color: #7ac0da;
- background-image: -ms-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
- background-image: -o-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
- background-image: -webkit-gradient(linear, left top, right top, color-stop(0, #7ac0da), color-stop(1, #a4d4e6));
- background-image: -webkit-linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
- background-image: linear-gradient(left, #7ac0da 0%, #a4d4e6 100%);
- color: #3e5667;
- padding: 20px 40px 30px 40px;
- }
-
- .featured hgroup.title h1, .featured hgroup.title h2 {
- color: #fff;
- }
-
- .featured p {
- font-size: 1.1em;
- }
-
-/* page titles */
-hgroup.title {
- margin-bottom: 10px;
+code {
+ padding: 3px;
+ margin: 0 3px;
+ box-shadow: 0 0 10px rgba(0,0,0,.1);
}
-hgroup.title h1, hgroup.title h2 {
- display: inline;
+pre code {
+ display: block;
+ box-shadow: none;
}
-hgroup.title h2 {
- font-weight: normal;
- margin-left: 3px;
+blockquote {
+ color: #666;
+ margin-bottom: 20px;
+ padding: 0 0 0 20px;
+ border-left: 3px solid #bbb;
}
-/* features */
-section.feature {
- width: 300px;
- float: left;
- padding: 10px;
+ul, ol, dl {
+ margin-bottom: 15px
}
-/* ordered list */
-ol.round {
- list-style-type: none;
- padding-left: 0;
+ul li {
+ list-style: inside;
+ padding-left: 20px;
}
- ol.round li {
- margin: 25px 0;
- padding-left: 45px;
- }
-
- ol.round li.zero {
- background: url("../Images/orderedList0.png") no-repeat;
- }
-
- ol.round li.one {
- background: url("../Images/orderedList1.png") no-repeat;
- }
-
- ol.round li.two {
- background: url("../Images/orderedList2.png") no-repeat;
- }
-
- ol.round li.three {
- background: url("../Images/orderedList3.png") no-repeat;
- }
-
- ol.round li.four {
- background: url("../Images/orderedList4.png") no-repeat;
- }
-
- ol.round li.five {
- background: url("../Images/orderedList5.png") no-repeat;
- }
-
- ol.round li.six {
- background: url("../Images/orderedList6.png") no-repeat;
- }
-
- ol.round li.seven {
- background: url("../Images/orderedList7.png") no-repeat;
- }
-
- ol.round li.eight {
- background: url("../Images/orderedList8.png") no-repeat;
- }
-
- ol.round li.nine {
- background: url("../Images/orderedList9.png") no-repeat;
- }
-
-/* content */
-article {
- float: left;
- width: 70%;
+ol li {
+ list-style: decimal inside;
+ padding-left: 20px;
}
-aside {
- float: right;
- width: 25%;
+dl dt {
+ font-weight: bold;
}
- aside ul {
- list-style: none;
- padding: 0;
- }
-
- aside ul li {
- background: url("../Images/bullet.png") no-repeat 0 50%;
- padding: 2px 0 2px 20px;
- }
-
-.label {
- font-weight: 700;
+dl dd {
+ padding-left: 20px;
+ font-style: italic;
}
-/* login page */
-#loginForm {
- border-right: solid 2px #c8c8c8;
- float: left;
- width: 55%;
+dl p {
+ padding-left: 20px;
+ font-style: italic;
}
- #loginForm .validation-error {
- display: block;
- margin-left: 15px;
- }
+hr {
+ height: 1px;
+ margin-bottom: 5px;
+ border: none;
+ background: url('../images/bg_hr.png') repeat-x center;
+}
- #loginForm .validation-summary-errors ul {
- margin: 0;
- padding: 0;
- }
+table {
+ border: 1px solid #373737;
+ margin-bottom: 20px;
+ text-align: left;
+ }
- #loginForm .validation-summary-errors li {
- display: inline;
- list-style: none;
- margin: 0;
- }
+th {
+ font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ padding: 10px;
+ background: #373737;
+ color: #fff;
+ }
- #loginForm input {
- width: 250px;
- }
+td {
+ padding: 10px;
+ border: 1px solid #373737;
+ }
- #loginForm input[type="checkbox"],
- #loginForm input[type="submit"],
- #loginForm input[type="button"],
- #loginForm button {
- width: auto;
- }
+form {
+ background: #f2f2f2;
+ padding: 20px;
+}
-#socialLoginForm {
- margin-left: 40px;
- float: left;
- width: 40%;
+img {
+ width: 100%;
+ max-width: 100%;
}
- #socialLoginForm h2 {
- margin-bottom: 5px;
- }
+/*******************************************************************************
+Full-Width Styles
+*******************************************************************************/
-#socialLoginList button {
- margin-bottom: 12px;
+.outer {
+ width: 100%;
}
-#logoutForm {
- display: inline;
+.inner {
+ position: relative;
+ max-width: 640px;
+ padding: 20px 10px;
+ margin: 0 auto;
}
-/* contact */
-.contact h3 {
- font-size: 1.2em;
+#forkme_banner {
+ display: block;
+ position: absolute;
+ top:0;
+ right: 10px;
+ z-index: 10;
+ padding: 10px 50px 10px 10px;
+ color: #fff;
+ background: url('../images/blacktocat.png') #0090ff no-repeat 95% 50%;
+ font-weight: 700;
+ box-shadow: 0 0 10px rgba(0,0,0,.5);
+ border-bottom-left-radius: 2px;
+ border-bottom-right-radius: 2px;
}
-.contact p {
- margin: 5px 0 0 10px;
+#header_wrap {
+ background: #212121;
+ background: -moz-linear-gradient(top, #373737, #212121);
+ background: -webkit-linear-gradient(top, #373737, #212121);
+ background: -ms-linear-gradient(top, #373737, #212121);
+ background: -o-linear-gradient(top, #373737, #212121);
+ background: linear-gradient(top, #373737, #212121);
}
-.contact iframe {
- border: 1px solid #333;
- margin: 5px 0 0 10px;
+#header_wrap .inner {
+ padding: 50px 10px 30px 10px;
}
-/* forms */
-fieldset {
- border: none;
- margin: 0;
- padding: 0;
+#project_title {
+ margin: 0;
+ color: #fff;
+ font-size: 42px;
+ font-weight: 700;
+ text-shadow: #111 0px 0px 10px;
}
- fieldset legend {
- display: none;
- }
-
- fieldset ol {
- padding: 0;
- list-style: none;
- }
-
- fieldset ol li {
- padding-bottom: 5px;
- }
-
-label {
- display: block;
- font-size: 1.2em;
- font-weight: 600;
+#project_tagline {
+ color: #fff;
+ font-size: 24px;
+ font-weight: 300;
+ background: none;
+ text-shadow: #111 0px 0px 10px;
}
-label.checkbox {
- display: inline;
+#downloads {
+ position: absolute;
+ width: 210px;
+ z-index: 10;
+ bottom: -40px;
+ right: 0;
+ height: 70px;
+ background: url('../images/icon_download.png') no-repeat 0% 90%;
}
-input, textarea {
- border: 1px solid #e2e2e2;
- background: #fff;
- color: #333;
- font-size: 1.2em;
- margin: 5px 0 6px 0;
- padding: 5px;
- width: 300px;
+.zip_download_link {
+ display: block;
+ float: right;
+ width: 90px;
+ height:70px;
+ text-indent: -5000px;
+ overflow: hidden;
+ background: url(../images/sprite_download.png) no-repeat bottom left;
}
-textarea {
- font-family: inherit;
- width: 500px;
+.tar_download_link {
+ display: block;
+ float: right;
+ width: 90px;
+ height:70px;
+ text-indent: -5000px;
+ overflow: hidden;
+ background: url(../images/sprite_download.png) no-repeat bottom right;
+ margin-left: 10px;
}
- input:focus, textarea:focus {
- border: 1px solid #7ac0da;
- }
-
- input[type="checkbox"] {
- background: transparent;
- border: inherit;
- width: auto;
- }
-
- input[type="submit"],
- input[type="button"],
- button {
- background-color: #d3dce0;
- border: 1px solid #787878;
- cursor: pointer;
- font-size: 1.2em;
- font-weight: 600;
- padding: 7px;
- margin-right: 8px;
- width: auto;
- }
-
- td input[type="submit"],
- td input[type="button"],
- td button {
- font-size: 1em;
- padding: 4px;
- margin-right: 4px;
- }
-
-/* info and errors */
-.message-info {
- border: 1px solid;
- clear: both;
- padding: 10px 20px;
+.zip_download_link:hover {
+ background: url(../images/sprite_download.png) no-repeat top left;
}
-.message-error {
- clear: both;
- color: #e80c4d;
- font-size: 1.1em;
- font-weight: bold;
- margin: 20px 0 10px 0;
+.tar_download_link:hover {
+ background: url(../images/sprite_download.png) no-repeat top right;
}
-.message-success {
- color: #7ac0da;
- font-size: 1.3em;
- font-weight: bold;
- margin: 20px 0 10px 0;
+#main_content_wrap {
+ background: #f2f2f2;
+ border-top: 1px solid #111;
+ border-bottom: 1px solid #111;
}
-.error {
- color: #e80c4d;
+#main_content {
+ padding-top: 40px;
}
-/* styles for validation helpers */
-.field-validation-error {
- color: #e80c4d;
- font-weight: bold;
+#footer_wrap {
+ background: #212121;
}
-.field-validation-valid {
- display: none;
-}
-input.input-validation-error {
- border: 1px solid #e80c4d;
-}
-input[type="checkbox"].input-validation-error {
- border: 0 none;
-}
+/*******************************************************************************
+Small Device Styles
+*******************************************************************************/
-.validation-summary-errors {
- color: #e80c4d;
- font-weight: bold;
- font-size: 1.1em;
-}
+@media screen and (max-width: 480px) {
+ body {
+ font-size:14px;
+ }
-.validation-summary-valid {
+ #downloads {
display: none;
-}
+ }
+ .inner {
+ min-width: 320px;
+ max-width: 480px;
+ }
-/* tables
-----------------------------------------------------------*/
-table {
- border-collapse: collapse;
- border-spacing: 0;
- margin-top: 0.75em;
- border: 0 none;
-}
+ #project_title {
+ font-size: 32px;
+ }
-th {
- font-size: 1.2em;
- text-align: left;
- border: none 0px;
- padding-left: 0;
-}
-
- th a {
- display: block;
- position: relative;
- }
-
- th a:link, th a:visited, th a:active, th a:hover {
- color: #333;
- font-weight: 600;
- text-decoration: none;
- padding: 0;
- }
-
- th a:hover {
- color: #000;
- }
-
- th.asc a, th.desc a {
- margin-right: .75em;
- }
-
- th.asc a:after, th.desc a:after {
- display: block;
- position: absolute;
- right: 0em;
- top: 0;
- font-size: 0.75em;
- }
-
- th.asc a:after {
- content: '';
- }
-
- th.desc a:after {
- content: '';
- }
+ h1 {
+ font-size: 28px;
+ }
+
+ h2 {
+ font-size: 24px;
+ }
+
+ h3 {
+ font-size: 21px;
+ }
+
+ h4 {
+ font-size: 18px;
+ }
+
+ h5 {
+ font-size: 14px;
+ }
+
+ h6 {
+ font-size: 12px;
+ }
+
+ code, pre {
+ min-width: 320px;
+ max-width: 480px;
+ font-size: 11px;
+ }
-td {
- padding: 0.25em 2em 0.25em 0em;
- border: 0 none;
-}
-
-tr.pager td {
- padding: 0 0.25em 0 0;
-}
-
-
-/********************
-* Mobile Styles *
-********************/
-@media only screen and (max-width: 850px) {
-
- /* header
- ----------------------------------------------------------*/
- header .float-left,
- header .float-right {
- float: none;
- }
-
- /* logo */
- header .site-title {
- margin: 10px;
- text-align: center;
- }
-
- /* login */
- #login {
- font-size: .85em;
- margin: 0 0 12px;
- text-align: center;
- }
-
- #login ul {
- margin: 5px 0;
- padding: 0;
- }
-
- #login li {
- display: inline;
- list-style: none;
- margin: 0;
- padding: 0;
- }
-
- #login a {
- background: none;
- color: #999;
- font-weight: 600;
- margin: 2px;
- padding: 0;
- }
-
- #login a:hover {
- color: #333;
- }
-
- /* menu */
- nav {
- margin-bottom: 5px;
- }
-
- ul#menu {
- margin: 0;
- padding: 0;
- text-align: center;
- }
-
- ul#menu li {
- margin: 0;
- padding: 0;
- }
-
-
- /* main layout
- ----------------------------------------------------------*/
- .main-content,
- .featured + .main-content {
- background-position: 10px 0;
- }
-
- .content-wrapper {
- padding-right: 10px;
- padding-left: 10px;
- }
-
- .featured .content-wrapper {
- padding: 10px;
- }
-
- /* page content */
- article, aside {
- float: none;
- width: 100%;
- }
-
- /* ordered list */
- ol.round {
- list-style-type: none;
- padding-left: 0;
- }
-
- ol.round li {
- padding-left: 10px;
- margin: 25px 0;
- }
-
- ol.round li.zero,
- ol.round li.one,
- ol.round li.two,
- ol.round li.three,
- ol.round li.four,
- ol.round li.five,
- ol.round li.six,
- ol.round li.seven,
- ol.round li.eight,
- ol.round li.nine {
- background: none;
- }
-
- /* features */
- section.feature {
- float: none;
- padding: 10px;
- width: auto;
- }
-
- section.feature img {
- color: #999;
- content: attr(alt);
- font-size: 1.5em;
- font-weight: 600;
- }
-
- /* forms */
- input {
- width: 90%;
- }
-
- /* login page */
- #loginForm {
- border-right: none;
- float: none;
- width: auto;
- }
-
- #loginForm .validation-error {
- display: block;
- margin-left: 15px;
- }
-
- #socialLoginForm {
- margin-left: 0;
- float: none;
- width: auto;
- }
-
-
- /* footer
- ----------------------------------------------------------*/
- footer .float-left,
- footer .float-right {
- float: none;
- }
-
- footer {
- text-align: center;
- height: auto;
- padding: 10px 0;
- }
-
- footer p {
- margin: 0;
- }
}
View
1 samples/MvcWebApiSiteTest/Controllers/CustomerController.cs
@@ -15,7 +15,6 @@ public Customer Get()
{
return new Customer { Name = "John Doe", Country = "Sweden" };
}
-
}
View
13 samples/MvcWebApiSiteTest/Controllers/HomeController.cs
@@ -0,0 +1,13 @@
+using System.Web.Http;
+using WebApiContrib.Formatting.Html;
+
+namespace MvcWebApiSiteTest.Controllers
+{
+ public class HomeController : ApiController
+ {
+ public View Get()
+ {
+ return new View("Index", null);
+ }
+ }
+}
View
7 samples/MvcWebApiSiteTest/MvcWebApiSiteTest.csproj
@@ -130,6 +130,7 @@
<Compile Include="App_Start\ViewConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\CustomerController.cs" />
+ <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
@@ -230,13 +231,13 @@
<Content Include="Images\orderedList9.png" />
<Content Include="Scripts\_references.js" />
<Content Include="Views\Web.config" />
- <Content Include="Views\_ViewStart.cshtml" />
- <Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Customer.cshtml" />
<Content Include="Views\CustomerViaAttrib.cshtml" />
<Content Include="Views\CustomerViaConfig.cshtml" />
<Content Include="Views\CustomerViaView.cshtml" />
+ <Content Include="Views\Shared\HttpError.cshtml" />
+ <Content Include="Views\Index.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
@@ -290,4 +291,4 @@
</Target>
<Target Name="AfterBuild">
</Target> -->
-</Project>
+</Project>
View
82 samples/MvcWebApiSiteTest/Views/Customer.cshtml
@@ -1,41 +1,41 @@
-@{
- _Layout = "~/Views/Shared/_Layout.cshtml";
-}
- <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
-
- <div id="body">
- <section>
-
- <div>
- <hgroup>
- <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Locate view by convention (the type of the model to render)</h1>
- </hgroup>
- </div>
- <p>
- Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
- </p>
- <p>
-
- </p>
-
- </section>
- </div>
-
- <script type="text/javascript">
-
- $("button").click(function () {
-
- $.ajax({
- url: '/api/customer',
- type: "GET",
- contentType: "application/json; charset=utf-8",
- success: function(data, status, xhr)
- {
- alert(data.Name);
- },
- error: function(xhr, status, error)
- {
- alert(error);
- }});
- });
-</script>
+@{
+ _Layout = "~/Views/Shared/_Layout.cshtml";
+}
+ <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
+
+ <div id="body">
+ <section>
+
+ <div>
+ <hgroup>
+ <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Locate view by convention (the type of the model to render)</h1>
+ </hgroup>
+ </div>
+ <p>
+ Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
+ </p>
+ <p>
+
+ </p>
+
+ </section>
+ </div>
+
+ <script type="text/javascript">
+
+ $("button").click(function () {
+
+ $.ajax({
+ url: '/customer',
+ type: "GET",
+ contentType: "application/json; charset=utf-8",
+ success: function(data, status, xhr)
+ {
+ alert(data.Name);
+ },
+ error: function(xhr, status, error)
+ {
+ alert(error);
+ }});
+ });
+</script>
View
96 samples/MvcWebApiSiteTest/Views/CustomerViaAttrib.cshtml
@@ -1,48 +1,48 @@
-<!DOCTYPE html>
-<html>
-
- <head>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
- </head>
-
- <body>
-
- <div id="body">
- <section>
-
- <div>
- <hgroup>
- <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using Attribute to locate View.</h1>
- </hgroup>
- </div>
- <p>
- Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
- </p>
- <p>
-
- </p>
-
- </section>
- </div>
-
- </body>
-
- <script type="text/javascript">
-
- $("button").click(function () {
-
- $.ajax({
- url: '/api/customer',
- type: "GET",
- contentType: "application/json; charset=utf-8",
- success: function(data, status, xhr)
- {
- alert(data.Name);
- },
- error: function(xhr, status, error)
- {
- alert(error);
- }});
- });
-</script>
-</html>
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
+ </head>
+
+ <body>
+
+ <div id="body">
+ <section>
+
+ <div>
+ <hgroup>
+ <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using Attribute to locate View.</h1>
+ </hgroup>
+ </div>
+ <p>
+ Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
+ </p>
+ <p>
+
+ </p>
+
+ </section>
+ </div>
+
+ </body>
+
+ <script type="text/javascript">
+
+ $("button").click(function () {
+
+ $.ajax({
+ url: '/customer',
+ type: "GET",
+ contentType: "application/json; charset=utf-8",
+ success: function(data, status, xhr)
+ {
+ alert(data.Name);
+ },
+ error: function(xhr, status, error)
+ {
+ alert(error);
+ }});
+ });
+</script>
+</html>
View
96 samples/MvcWebApiSiteTest/Views/CustomerViaConfig.cshtml
@@ -1,48 +1,48 @@
-<!DOCTYPE html>
-<html>
-
- <head>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
- </head>
-
- <body>
-
- <div id="body">
- <section>
-
- <div>
- <hgroup>
- <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using Configuration to locate View.</h1>
- </hgroup>
- </div>
- <p>
- Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
- </p>
- <p>
-
- </p>
-
- </section>
- </div>
-
- </body>
-
- <script type="text/javascript">
-
- $("button").click(function () {
-
- $.ajax({
- url: '/api/customer',
- type: "GET",
- contentType: "application/json; charset=utf-8",
- success: function(data, status, xhr)
- {
- alert(data.Name);
- },
- error: function(xhr, status, error)
- {
- alert(error);
- }});
- });
-</script>
-</html>
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
+ </head>
+
+ <body>
+
+ <div id="body">
+ <section>
+
+ <div>
+ <hgroup>
+ <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using Configuration to locate View.</h1>
+ </hgroup>
+ </div>
+ <p>
+ Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
+ </p>
+ <p>
+
+ </p>
+
+ </section>
+ </div>
+
+ </body>
+
+ <script type="text/javascript">
+
+ $("button").click(function () {
+
+ $.ajax({
+ url: '/customer',
+ type: "GET",
+ contentType: "application/json; charset=utf-8",
+ success: function(data, status, xhr)
+ {
+ alert(data.Name);
+ },
+ error: function(xhr, status, error)
+ {
+ alert(error);
+ }});
+ });
+</script>
+</html>
View
96 samples/MvcWebApiSiteTest/Views/CustomerViaView.cshtml
@@ -1,48 +1,48 @@
-<!DOCTYPE html>
-<html>
-
- <head>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
- </head>
-
- <body>
-
- <div id="body">
- <section>
-
- <div>
- <hgroup>
- <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using View to locate View.</h1>
- </hgroup>
- </div>
- <p>
- Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
- </p>
- <p>
-
- </p>
-
- </section>
- </div>
-
- </body>
-
- <script type="text/javascript">
-
- $("button").click(function () {
-
- $.ajax({
- url: '/api/customer',
- type: "GET",
- contentType: "application/json; charset=utf-8",
- success: function(data, status, xhr)
- {
- alert(data.Model.Name);
- },
- error: function(xhr, status, error)
- {
- alert(error);
- }});
- });
-</script>
-</html>
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
+ </head>
+
+ <body>
+
+ <div id="body">
+ <section>
+
+ <div>
+ <hgroup>
+ <h1>Welcome '@Model.Name' to ASP.NET Web API Razor Formatter! Using View to locate View.</h1>
+ </hgroup>
+ </div>
+ <p>
+ Using the same URL "api/values" but using AJAX: <button>Press to show content!</button>
+ </p>
+ <p>
+
+ </p>
+
+ </section>
+ </div>
+
+ </body>
+
+ <script type="text/javascript">
+
+ $("button").click(function () {
+
+ $.ajax({
+ url: '/customer',
+ type: "GET",
+ contentType: "application/json; charset=utf-8",
+ success: function(data, status, xhr)
+ {
+ alert(data.Model.Name);
+ },
+ error: function(xhr, status, error)
+ {
+ alert(error);
+ }});
+ });
+</script>
+</html>
View
62 samples/MvcWebApiSiteTest/Views/Index.cshtml
@@ -0,0 +1,62 @@
+
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <meta charset='utf-8' />
+ <meta http-equiv="X-UA-Compatible" content="chrome=1" />
+ <meta name="description" content="WebApiContrib : Community Contributions for ASP.NET Web API" />
+
+ <link rel="stylesheet" type="text/css" media="screen" href="/Content/Site.css">
+
+ <title>WebApiContrib</title>
+ </head>
+
+ <body>
+
+ <!-- HEADER -->
+ <div id="header_wrap" class="outer">
+ <header class="inner">
+ <a id="forkme_banner" href="https://github.com/WebApiContrib/WebAPIContrib">Fork Me on GitHub</a>
+
+ <h1 id="project_title">WebApiContrib</h1>
+ <h2 id="project_tagline">Community Contributions for ASP.NET Web API</h2>
+
+ <section id="downloads">
+ <a class="zip_download_link" href="https://github.com/WebApiContrib/WebAPIContrib/zipball/master">Download this project as a .zip file</a>
+ <a class="tar_download_link" href="https://github.com/WebApiContrib/WebAPIContrib/tarball/master">Download this project as a tar.gz file</a>
+ </section>
+ </header>
+ </div>
+
+ <!-- MAIN CONTENT -->
+ <div id="main_content_wrap" class="outer">
+ <section id="main_content" class="inner">
+ <h3>WebApiContrib</h3>
+
+<p>WebApiContrib is a collection of projects and samples built by the community for to enhance and improve the <a href="http://www.asp.net/web-api">ASP.NET Web API framework.</a></p>
+
+<p>More information will be coming very soon!</p>
+ </section>
+ </div>
+
+ <!-- FOOTER -->
+ <div id="footer_wrap" class="outer">
+ <footer class="inner">
+ <p class="copyright">WebApiContrib maintained by <a href="https://github.com/WebApiContrib">WebApiContrib</a></p>
+ <p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
+ </footer>
+ </div>
+
+ <script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-30452127-1']);
+ _gaq.push(['_trackPageview']);
+ (function () {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ </script>
+ </body>
+</html>
View
33 ...cWebApiSiteTest/Views/Shared/Error.cshtml → ...ApiSiteTest/Views/Shared/HttpError.cshtml
@@ -1,16 +1,19 @@
-@{
- Layout = null;
-}
-
-<!DOCTYPE html>
-<html>
-<head>
- <meta name="viewport" content="width=device-width" />
- <title>Error</title>
-</head>
-<body>
- <h2>
- Sorry, an error occurred while processing your request.
- </h2>
-</body>
+<!DOCTYPE html>
+<html>
+<head>
+ <meta name="viewport" content="width=device-width" />
+ <title>Error</title>
+</head>
+<body>
+ <h2>
+ Sorry, an error occurred while processing your request.
+ </h2>
+
+ <div>
+ @foreach( var value in Model.Values) {
+ @value
+ }
+ </div>
+
+</body>
</html>
View
3 samples/MvcWebApiSiteTest/Views/_ViewStart.cshtml
@@ -1,3 +0,0 @@
-@{
- Layout = "~/Views/Shared/_Layout.cshtml";
-}
View
77 src/WebApiContrib.Formatting.Html/Formatters/HtmlMediaTypeViewFormatter.cs
@@ -35,34 +35,7 @@ public HtmlMediaTypeViewFormatter(string siteRootPath = null, IViewLocator viewL
_siteRootPath = siteRootPath;
}
- private IViewLocator ViewLocator
- {
- get
- {
- if (_viewLocator != null)
- return _viewLocator;
-
- if (GlobalViews.DefaultViewLocator != null)
- return GlobalViews.DefaultViewLocator;
-
- throw new ConfigurationErrorsException("No ViewLocator is specidied");
- }
- }
-
- private IViewParser ViewParser
- {
- get
- {
- if (_viewParser != null)
- return _viewParser;
-
- if (GlobalViews.DefaultViewParser != null)
- return GlobalViews.DefaultViewParser;
-
- throw new ConfigurationErrorsException("No ViewParser is specidied");
- }
- }
-
+
public override bool CanWriteType(Type type)
{
return true;
@@ -83,13 +56,21 @@ public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, Htt
if (_viewLocator == null || _viewParser == null)
{
var config = request.GetConfiguration();
+
if (config != null)
{
+ IViewLocator viewLocator = null;
+ IViewParser viewParser = null;
+
var resolver = config.DependencyResolver;
- IViewLocator viewLocator = (IViewLocator) resolver.GetService(typeof (IViewLocator));
- IViewParser viewParser = (IViewParser) resolver.GetService(typeof (IViewParser));
- if (viewLocator != null && viewParser != null)
- return new HtmlMediaTypeViewFormatter(_siteRootPath, viewLocator, viewParser);
+
+ if (_viewLocator == null)
+ viewLocator = (IViewLocator) resolver.GetService(typeof (IViewLocator));
+
+ if (_viewParser == null)
+ viewParser = (IViewParser) resolver.GetService(typeof (IViewParser));
+
+ return new HtmlMediaTypeViewFormatter(_siteRootPath, viewLocator, viewParser);
}
}
@@ -98,10 +79,6 @@ public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, Htt
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
{
- //Type can be of type HttpError, it will happen if the ApiController throws an exception, there is nothing in this code at the moment
- //that will handle that issue. This code will try to locate a HttpError.cshtml file, even if it exists, the header will be 500 and
- //the HttpError page will not be displayed, only the default 500 error page.
-
return TaskHelpers.RunSync(() =>
{
var encoding = SelectCharacterEncoding(content.Headers);
@@ -122,6 +99,34 @@ private byte[] ParseView(Type type, object model, Encoding encoding)
return ViewParser.ParseView(view, viewTemplate, encoding);
}
+ private IViewLocator ViewLocator
+ {
+ get
+ {
+ if (_viewLocator != null)
+ return _viewLocator;
+
+ if (GlobalViews.DefaultViewLocator != null)
+ return GlobalViews.DefaultViewLocator;
+
+ throw new ConfigurationErrorsException("No ViewLocator is specified");
+ }
+ }
+
+ private IViewParser ViewParser
+ {
+ get
+ {
+ if (_viewParser != null)
+ return _viewParser;
+
+ if (GlobalViews.DefaultViewParser != null)
+ return GlobalViews.DefaultViewParser;
+
+ throw new ConfigurationErrorsException("No ViewParser is specified");
+ }
+ }
+
private static string GetViewName(object model)
{
var modelType = model.GetType();
View
3 src/WebApiContrib.Formatting.Html/View.cs
@@ -13,7 +13,8 @@ internal View(string viewName, object model, Type modelType)
Model = model;
ViewName = viewName;
- ModelType = modelType ?? model.GetType();
+ if (modelType != null)
+ ModelType = model.GetType();
}
public object Model { get; protected set; }
View
16 src/WebApiContrib.Formatting.Razor/RazorViewParser.cs
@@ -38,11 +38,21 @@ public RazorViewParser(ITemplateResolver resolver)
public byte[] ParseView(IView view, string viewTemplate, System.Text.Encoding encoding)
{
- _templateService.Compile(viewTemplate, view.ModelType, view.ModelType.Name);
-
- var parsedView = _templateService.Run(view.ModelType.Name, view.Model);
+ var parsedView = GetParsedView(view, viewTemplate);
return encoding.GetBytes(parsedView);
}
+
+ private string GetParsedView(IView view, string viewTemplate)
+ {
+ if (view.ModelType == null)
+ {
+ _templateService.Compile(viewTemplate, view.ViewName);
+ return _templateService.Run(view.ViewName);
+ }
+
+ _templateService.Compile(viewTemplate, view.ModelType, view.ViewName);
+ return _templateService.Run(view.ViewName, view.Model);
+ }
}
}

0 comments on commit 64c2382

Please sign in to comment.