Category Archives: MVC

ASP.NET Core Real Power: Features And Benefits

Introduction

ASP.NET Core 1.0 is not a continuation of ASP.NET 4.6. It is a whole new framework, a side-by-side project which happily lives alongside everything else we know. It is an actual re-write of the current ASP.NET 4.6 framework, but much smaller and a lot much more modular. There is no System. Web namespace anymore and everything which came with it.

It is the framework you want to use for web development with .NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features. ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn’t have SignalR or Web Pages. It doesn’t yet support VB or F#.

If you have any experience with MVC or Web API over the last few years, you will notice some familiar features.This sequence of tutorials, will help you write an application using ASP.NET Core that can create, edit, and view data from a database.

Advantages of ASP.NET Core

Open Source:

ASP.NET Core is open source and available on GitHub,Which help to reduce the cost of hosting.NET application.

Platform Independent (Cross Platform Support):

ASP.NET Core 1.0 is a big fundamental change to the ASP.NET landscape and it is open source. ASP.NET Core is supported on Windows, Mac and Linux OSX

Built from scratch:

ASP.NET Core is not like an enhancement to ASP.NET 4.5 but it has been built from scratch. A lot of new features have been added to it and some of the existing features has been dropped also. To support Cross Platform and improve performance some existing features have been removed.

Modular Web Framework:

Asp.Net core everything is managed using nugget package, so it’s easy to upgrade new framework without releasing new .net framework version. In ASP.NET Core, a community can just release new NuGet package version and you will get latest changes by updating your packages. The .NET developer has the ability to pick and choose which ASP.NET features to include in their solutions. This opt-in model allows developers to be more deliberate with regard to which libraries are included in their projects

Dependency Injection:

Dependency injection is integrated into the framework for achieving loose coupling between objects and their collaborators.Third party products such as Autofac should still be available as an alternative to the build-in ASP.NET DI functionality.

Combination of MVC and WEB.API

In previous versions of ASP.NET, MVC and WEB.API were based on different versions of the framework ie., System.Web.Mvc and System.Web.Http/System.Net.Http, respectively. This has been removed and its been integrated with ASP.NET CORE 1.0 MVC 6. There is now a single set of objects within a single namespace (Microsoft.AspNet.Mvc). This standardized approach simplifies developing both MVC and WEB.API endpoints.

What do you think?

I hope you have basic about ASP .NET Core and its advantage . I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

Implementing jQuery.ajax() using Jquery

What is JQuery Ajax?

AJAX is standing for Asynchronous JavaScript and XML. It helps us to fetch the information from the server without reloading the page (ie., without refresh)JQuery is a great tool which provides a rich set of AJAX methods to develop great web application. jQuery provides the $.ajax method and several methods to make it easier to work with XHRs across browsers.

$.ajax

We can use the jQuery $.ajax() method in a different ways, let we discuss one by one.

  • we can pass it a configuration object as its argument
  • we can pass it a URL and an optional configuration object

SYNTAX: 

  • $.ajax(url,[options])
  • $.ajax([options])

Option Parameter:

Here i have listed few parameters which is using frequently.

Options Description
accepts The content type sent in the request header that tells the server what kind of response it will accept in return.
async By default, all requests are sent asynchronously. Set it false to make it synchronous.
beforeSend A callback function to be executed before Ajax request is sent.
cache A boolean indicating browser cache. Default is true.
complete A callback function to be executed when request finishes.
contentType A string containing a type of content when sending MIME content to the server.
data A data to be sent to the server. It can be JSON object, string or array.
dataType Type of data that we receiving back from the server.
error A callback function to be executed when the request fails.
headers An object of additional header key/value pairs to send along with request.
isLocal Allow the current environment to be recognized as local.
statusCode A JSON object containing numeric HTTP codes and functions to be called when the response has the corresponding code.
success A callback function to be executed when Ajax request succeeds.
timeout A number value in milliseconds for the request timeout.
type A type of http request for operation e.g. POST, PUT and GET. Default is GET.
url A string containing the URL to which the request is sent.

 

1) we can pass it a configuration object as its argument:

The $.ajax() method offers the ability to specify both success and failure callbacks. It have a felxibility
to take a configuration object, which can be defined separately. This approach make the developer to write reusable code.

var updateSuccessfully = function( obj ) {
$( '#divSuccess').html( "Updated successfully" );
};

var showError = function( req, status, err ) {
console.log( 'Went wrong while performing operation', status, err );
};

var ajaxUpdateRequest = {
url: '/dotnethelpers/UpdateUsers',
dataType: 'json',
success: updateSuccessfully,
error: showError
};

// Initiate the request
$.ajax(ajaxUpdateRequest);

Code Explanation:

updateSuccessfully,showError -: Both are methods created for handling success & error.
ajaxUpdateRequest :  It is declared as a separate method for handling the ajax operation. Inside the code, if it return success then ajax success will call the updateSuccessfully method and showError method when ajax operation fails. This approach make the developer to write reusable code.

2) we can pass it a URL and an optional configuration object

In this type, we can also call the $.ajax() method by passing it a URL and an optional configuration object.
This is very useful if we want to use the default configuration for $.ajax(), or if you want to use the same configuration for several URLs

$.ajax( '/dotnethelpers/UpdateUsers', {
type: 'GET',
dataType: 'json',
success: function( resp ) {
console.log( "Operation Performed Successfully" );
},
error: function( req, status, err ) {
console.log( 'Went wrong while performing operation',, status, err );
}
});

Code Explanation:

In above code, we can take advantage of passing url, type, datatype etc as an parameter. so it can be used by several other method for performing operation with different arguments.

 

Ajax Helpers in ASP.NET MVC

Ajax Helpers:

We already aware that we use HTML helpers to create a forms with the user’s controls. ASP.NET MVC provides another option that is Ajax helpers functionality to our web applications. The main purpose of AJAX Helpers are used to create AJAX enabled forms and links which performs request asynchronously.

When to use?

Here big question will raise, both HTML helper and AJAX helper method generate the anchor tag then why we need to use the @AJAX.ActionLink instead of @HTML.ActionLink ? The solution will be,

  • When the user clicks on the link and it want to redirect to another page then we can use @HTML.ActionLink.
  • When the user clicks on the link and don’t want to redirect to different page, need to stay on the same page (without Post Back), then we can go for @AJAX.ActionLink.

Difference between Html and Ajax helper:

  • HTML helper class performs request synchronously.
  • Ajax helper class performs request asynchronously.

Namespace: System.Web.Mvc

Unobtrusive AJAX

ASP.NET MVC supports unobtrusive Ajax which is based on jQuery. The unobtrusive Ajax is used to define the Ajax features through in our application. While creating project in ASP.NET MVC, the jquery-unobtrusive-ajax.js and jquery-unobtrusive-ajax.min.js files has added automatically to our application as shown below.

Ajax helper Properties and its use :

Property Description
Url Specify the URL that will be requested from the server.
Confirm Given message will be displayed in a confirm dialog to the end user.The ajax call will trigger after clicked OK button
OnBegin The javaScript function name in OnBegin will be intiated at the BEGINNING of the Ajax request.
OnComplete The javaScript function name in OnComplete will be intiated at the END of the Ajax request.
OnSuccess The javaScript function name in OnSuccess will be intiated when Ajax request succeed.
OnFailure The javaScript function name in OnFailure will be intiated when Ajax request failed
UpdateTargetId Specify the target container’s Id that will be populated with the HTML returned by the action method.
InsertionMode Specify the way of populating the target container. The possible values are InsertAfter, InsertBefore and Replace (which is the default).
LoadingElementId Specify progress message container’s Id to display a progress message to the end user while processing the Ajax request.
LoadingElementDuration Specify a time duration for controls the duration of the progress message during the Ajax request.

Example 1 : With Simple Ajax call

Below example code shows how to use AJAX action link in Asp.Net MVC.

@Ajax.ActionLink("Get User Details", "GetDetails", new AjaxOptions
{
UpdateTargetId = "divGetAllUsers",
HttpMethod = "GET",
OnSuccess = "fnSuccess",
})

OUTPUT:

Run the application and  we can see that the he ajax helper Action link has converted to the HTML anchor link element as shown below.

<a data-ajax=”true” data-ajax-method=”GET” data-ajax-mode=”replace” data-ajax-success=”fnSuccess” data-ajax-update=”#divGetAllUsers” href=”/Ajaxhelpers/GetDetails”>Get User Details</a>

Example 2 : With “Confirm” properties

View:

<h2>Index</h2>
@Ajax.ActionLink("Get User Details", "GetDetails", new AjaxOptions
{
UpdateTargetId = "divGetAllUsers",
Confirm = "Aru u sure want to Get all the USER DETAILS",
HttpMethod = "GET",
OnSuccess = "fnSuccess",
})


OUTPUT:

Run the application and click the “Get User Details”, then it will show the pop up for confirmation to proceed. If u click “Ok” then it will process the Ajax request. If we click “cancel” then it wont process the Ajax request.

Note:

The following things need to be required before using ajax helper class.

Required reference:

<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>

Required Configuration:

<appSettings>
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

ActionVerbs Attributes in Asp.Net MVC

ActionVerbs are used when we want to control the selection of an action method based on a Http request method. For example, if we have two action method with same name then it can be respond based upon the HTTP request type(one action has  to respond to Http Get and another method have respond to Http Post). ASP.NET MVC provides attributes to tweak how the actions can be selected based on the name.

Different types of ActionVerbs

ASP.NET MVC supports different types of ActionVerbs.

  • HttpVerbs.Get – retrieve the details from the server. Parameters will be appended in the query string.
  • HttpVerbs.Post – submit new details.
  • HttpVerbs.Put – Use to update an existing information.
  • HttpVerbs.Delete – To delete an existing information.
  • HttpVerbs.Head – Identical to GET except that server do not return message body
  • HttpVerbs.Patch – Requests that a set of changes described in the request entity be applied to the resource identified by the Request
  • HttpVerbs.Options – Represents a request for information about the communication options available on the request/response identified by the Request

In ASP .NET MVC, it can be achieve in two different ways.

Method 1: AcceptVerbs Attribute

We can apply multiple http verbs using AcceptVerbs attribute by using OR operator.

public class dotnethelpersController : Controller
{
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult EditEmpDetails(int id)
{
// retrieve the Details
}

Method 2: shortcut attributes

public class dotnethelpersController : Controller
{
[HttpGet]
public ActionResult EditEmpDetails(int id)
{
}

[HttpPost]
public ActionResult EditEmpDetails(string empCode)
{
}

Points to Remember :

  • If we declare the ActionVerbs then the action methods are selected based on the request methods.
  • Using AcceptVerbs attribute, we can use multiple action verbs in a single action method
  • Multiple action methods can have same name by declaring with different action verbs.

ValidateInput Attribute in ASP.NET MVC

In some scenario, we need to send HTML value/content as input to our application from the view to the controller. In some time we use HTML Editors to save the HTML content if the end user accept. By default, ASP.NET MVC framework prevents you from submitting the HTML content/potentially malicious content to the controller, for avoiding the cross site scripting attack. This feature is called request validation.

Used Version Detail : Visual studio 2013, Version 4.5, MVC 5

Controller:

This is the simple ValideInput controller and it will render the view as output. And in the form submission, it will redirect to GetDescription() action and bind the view. In default, ValidateInput attribute parameter is true (ValidateInput(true)).

public ActionResult ValideInput()
{
return View();
}
public ActionResult GetDescription(FormCollection _inputDescription)
{
 //your logic
 return View();
}

View:

Here it is the view for getting the form data from the user, which contain one textbox and submit button inside the BeginForm. After user submission it will redirect to the GetDescription action method inside the dotnethelpers controller.

<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
@{
using (Html.BeginForm("GetDescription", "dotnethelpers"))
{
<input type="txtDescription" name="description" /> <br />
<input type="submit" value="Submit Form" />
}
}
</div>
</body>
</html>

Output :

As per below screen, we are entering a content with HTML elements. And once we click on the submit button, then it will throw the error as like below because, in default ASP.NET MVC prevents the HTML element as form data. In simple, ASP.NET MVC cannot send HTML values to the controller.

Note:

This is not an issue, it is default security validation handling by the ASP.NET MVC. In some scenario we need to override this  security by using the ValidateInput attribute to prevent HTML explicitly.

Implementing ValidateInput attribute:

In default, ValidateInput parameter is true (ValidateInput(true).

[ValidateInput(false)] public ActionResult GetDescription(FormCollection _inputDescription) { return View(); }

GetDescription View:

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>GetDescription</title>
</head>
<body>
<div> 
<h1>GetDescription View : Making validation using ValidateInput(false) attribute</h1>
</div>
</body>
</html>

Run the application and apply the Html element as input (Ex : http://localhost:62536/dotnethelpers/ValideInput).
Now its redirect to the “GetDescription View” instead of throwing the potential error as shown below.

 

Make Note Before Use:

  • XSS (Cross site scripting) is a security attack where this can inject malicious code while input the entry.
  • In ASP.NET MVC, it prevented the above attract by default.
  • ValidateInput attribute is unsafe because it still allows others to inject malicious code.
  • It can be applied on the controller/action level, but not for model property.
  • Model level can be handle by using [AllowHtml] attribute
  • public class UserDetails
    {
    [AllowHtml]
    public string userDescription { get; set; }
    }

 

Happy codding !!!

Error Handling in ASP.Net MVC Using HandleError Attribute

Exception handling plays an important role in any application, whether it is a web application or a Windows Forms application.Implementing a proper exception handling in our application is important. In most scenario, after we caughtthe exception, we have to log the exception details or show a friendly message to the user. ASP.NET MVC provides built-in features for exception handling through exception filters. The HandleError is the default built-in exception filter which is used to handle the exception. In this post, we are going to discuss about the HandleError filter.

What HandleError filter do?

ASP.Net MVC HandleError attribute provides a built-in exception filter. The HandleError attribute in ASP.NET MVC can be applied over the action method as well as a controller or at the global level for handle the exception in controller and action level. While creating our application, the HandleError attribute is automatically included within the Global.asax.cs and registered in FilterConfig.cs as shown below.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}

It can applied at the global level as well. The HandleError attribute is the default implementation of IExceptionFilter. The HandleError filter handles the exceptions which been raised at the controller/actions. Then it return a custom error view. Let we discuss detail about with example.

Limitation of HandleError Filter:

  • It catch only 500 Http error and not catch HTTP errors like 404,401 ..
  • It has no support to log the exceptions. We can log the exception by create custom error filter by implementing HandleError class.
  • It doesn’t catch the errors that occur outside the controllers and also not catch the ajax calls error too.

Properties in HandleError Attribute

The HandleError Error attribute has a few properties for handling the exception.

ExceptionType: It is used to specify the type of exception to be catch. If this property is not set then it will handles all type exceptions.

TypeId: Set the unique identifier for this attribute

View: Need to specify the name of view. It will redirect to particular view when exception occur.

Master: Master View for displaying the exception.

Example:

Used Version Detail : Visual studio 2013, Version 4.5, MVC 5

While creating ASP.NET MVC application the error.cshtml view is created automatically under the shared folder. Creating our own CustomError.cshtml view for displaying error with custom content for the user.

Controller:

HandleErrorAttribute controller has an index action method. From the below code, When the NullReferenceException error happens in the action Index, then the ASP.NET MVC HandleError attribute will find in a view called “CustomError”, in the shared folder and renders it to the user. (Placing in the “Shared” Folder, will be shared with all controllers).

public class HandleErrorAttributeController : Controller
{
[HandleError(View = "CustomError")]
public ActionResult Index()
{
throw new NullReferenceException();
}
}

Sample Attribute :

  1. [HandleError(ExceptionType = typeof(System.Data.DataException), View = “DatabaseError”)]
  2. [HandleError(ExceptionType = typeof(NullReferenceException), View = “NullReferenceError”)]

Web.config

The HandleError filter works only if the <customErrors> section is turned on in web.config.

<system.web>
<customErrors mode="On"></customErrors>
</system.web>

Output :

Note:

  • The HandleError filter works only if the <customErrors> section is turned on in web.config.
  • We can use HandleError Attribute for the entire application by registering it as a global error handler.

 

LowercaseRoutes – ASP.NET MVC routes to lowercase URLs

About this Article

We aware of that our Asp .Net MVC application generate mixed-case URLs like https://dotnet-helpers.com/Home/About or https://dotnet-helpers.com/home/about. So if we type URLs then it wont consider the upper case or lower case. In ASP.NET MVC, route generates outgoing URLs based on the casing of our controller and action names. By default, ASP.NET MVC controllers are classes and actions are methods,so these outgoing URLs are likely be camel-case.

Having Two URLs make problem in Search Rankings:

In ASP.NET MVC, the URLs generated by the routing mechanism are based on the controller and action names. Technically be considered , this will lead to duplicate pages with the same content. Most SEOs will recommend sticking to have only one version.

Solution :

LowercaseUrls property on the RouteCollection class has introduced in ASP .NET 4.5. Using this property we can lowercase all of our URLs.

Eg : routes.LowercaseUrls = true;

Example :

RouteConfig.cs

Include below pieace of code in the RouteConfig.cs file to convert all the URLs in to lowercase.

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.LowercaseUrls = true;

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

}
}

Controller:

A simple controller which has two action method namely LowerCaseUrls and LoadUserDetails.

public class dotnethelpersController : Controller
{
   public ActionResult LowerCaseUrls()
   {
      return View();
   }

   public ActionResult LoadUserDetails()
   {
       return View();
   }
}

LowerCaseUrls.cshtml :

<!DOCTYPE html>

<html>
<head>
<title>LowerCaseUrls</title>
</head>
<body>
<div>
      @Html.ActionLink("Home", "LoadUserDetails", "Dotnethelpers")
</div>
</body>
</html>

Output:

After clicking the HOME Link it redirecting to the dotnethelpers/loaduserdetails instead of Dotnethelpers/LoadUserDetails

 

Keep Happy Coding !!!

 

Donut Hole Caching in ASP.NET MVC

Donut Hole Caching is the inverse of Donut cache. As the previous statement, the Donut Caching is used to cache a maximum portion of the view/page, but Donut Hole Caching is used to cache only small portion of the view/page. More about Donut Caching refer here . Donut Hole caching procure by OutputCache and ChildActionOnly attribute.

What is in Mind?

Q1 : What is different type of caching in MVC
We can use OutputCache, DonutCache and Donut Hole Cache to cache the content.

Q2 : When can we implement?
OutputCache – Use when need to cache Whole page/View
DonutCache – Use to cache Whole page expect small portion of it.
Donut Hole Cache – Need to cache small portion instead of caching whole page

When to use ?

Let consider the scenario, having a website which contains the home page with dynamic content(maximum of the page) which load the content based on the user login. And also it has News feed section which contain small portion of the page(static content for all user).

In this scenario, we need to cache the common portion of the page for all the users. So here we cache News feed section instead of dynamic content.

How to Implement ?

In ASP.NET MVC, we can cache whole action with OutputCache Attribute. In mean while if we do not want to cache the entire action, we just want to cache the small portion of page/view. Then this can be achieved by using combination of ChildActionExtensions and OutputCache Attribute.

Controller:

From the below code, the LoadNewsFeed content (ie., loading partial view) in the Index view has cached for 60 seconds for all users expect static content which is specified inside the view.The ChildActionOnly attribute ensures that an action method can be called only as a child method from within a view. In simple, ChildActionOnly attribute are treated as non-action method (It treated as normal method). More about ChildActionOnly

public class DonutCacheController : Controller
{
public ActionResult Index()
{
ViewBag.CurrentDataTimeMessage = DateTime.Now.ToString();
return View();
}

[ChildActionOnly] [OutputCache(Duration = 60)] public ActionResult LoadNewsFeed() { ViewBag.CurrentDataTimeMessage = DateTime.Now.ToString(); return View(); } }

View

Creating a view with displaying current time and render LoadNewsFeed partial view in it.

<h2>Index</h2>
<h3>Message from DonutCache -> Index </h3>
<h3>@ViewBag.CurrentDataTimeMessage</h3>

@Html.Action("LoadNewsFeed")

Output:

Run the application, when we browse DonutCache controller then it will load the index view. If we refresh the page before 60 seconds, then the index view will refresh because it has not cached . But LoadNewsFeed has not refreshed every time because it has been cached by using Donut Hole caching.

 

Keep Happy coding…

 

 

Donut Caching with Asp.Net MVC

Donut caching used to cache an entire web page except for one or more small portion of the page. In other words, suppose we want to cache a maximum portion of the view except the minimum portion then we can finalize to use DonutCache. I know while start reading this, many questions will arise. Let us discuss this in “What is in Mind”  section.

What is in Mind?

Q1 : At meantime, we think what will  happen when we use Output Caching ?
The output cache will cache the entire web page.

Q2 : However, what can we do when we want to do the inverse of the Donut Caching?
we want to use Donut hole cache instead of the DonutCache to cache the small portion of the view instead of maximum portion (inverse of DonutCache)

When to use Donut Cache?

Let we assume, having a web site which contains the home page with displaying login user name (small portion will be in dynamic) , and the remaining are static content.

Bad Approach:

If you want to cache users by using OutputCache with VaryByParam User ID, then the entire page will be cached every time for each user with a different user name. This is a bad approach because if 5000 users logged into the site, then there will be 5000 pages have been cached.

Good Approach :

In this scenario, we can use DonutCaching. It is useful when page containing most of the information is rarely Changed and few items changing dynamically( based on the parameter).

Including MVCDonutCaching using NuGet Package:

We can install MVCDonutCaching using NuGet or using Package Manager Console Go to Tools -> Library Package Manager -> Package Manager Console, then type the command “Install-package MvcDonutCaching” in the console as shown below image.

Example :

Once we installed MvcDonutCaching package, we can add the DonutOutputCache attribute to the action or to the controller. Most of the parameter type of OutputCache attribute are also available in the DonutCache as shown below.

 

Controller :

From the below code, the static content in the Index view has cached for 30 seconds for all users expect dynamic content which is specified inside the view(ie., loading partial view).

public class DonutCacheController : Controller
 {
 [DonutOutputCache(Duration = 30)]
 public ActionResult Index()
 {
 ViewBag.CurrentDataTimeMessage = DateTime.Now.ToString();
 return View();
 }

 public ActionResult LoadUserDetail()
 {
 ViewBag.CurrentDataTimeMessage = DateTime.Now.ToString();
 return View();
 }
 }

Partial view :

Create LoadUserDetail.cshtml partial view and display the time from ViewBag. This partial view has been called in the DonutCache ->Index(view)

<h2> Message from Partial View - LoadUserDetail</h2> 
@ViewBag.CurrentDataTimeMessage<br>

View :

Here i am creating view with displaying current time and render LoadUserDetail partial view in it.

<h2>Index</h2>
<h2>Message from DonutCache -> Index </h2>
@ViewBag.CurrentDataTimeMessage

@Html.Action("LoadUserDetail", "DonutCache", new { name = "test" }, true)

OUTPUT :

While running the application, when we browse DonutCache controller then it will load the index view. If we refresh the page before 30 seconds, then index view will not refresh because it has been cached by the DonutCache (Time remain the same in the view, but time from the partial view had been updated for every refresh as shown below) . But LoadUserDetail has been refreshed every time because it hasn’t caught in cache as show below.

For more detail on caching and output caching.

Keep Happy Coding !!!

Enable Errors of Our ASP.NET MVC Views at Compile Time

In this post, we are going to discuss about how to capture “view” errors at compile time. By default, ASP.NET MVC projects won’t compile the views on the building process of our application. But don’t think Visual studio not handle this. As per below screen shot, it’s showing views error as warning in the Error List window, but we won’t consider the warning while running the application. 

All things are handling her. But many of us really won’t check this warning, as shown above. What we can do here is a fairly simple action to get this blow up on compile time. Let we discuss details about this.

STEP 1:

Right-click on your project’s  solution explorer and click Unload Project as shown in below image

STEP 2: After project unloaded,

After the project unloaded, right-click the project and choose Edit “Your project name” (. csproj) and MvcBuildViews node from false to true (for handlingthe error in compile time) and save the file.

STEP 3:

Reload the project and build the solution. Now we can see the “0 succeed , 1 failed” in the output window.