In ASP.NET MVC: All possible ways to call Controller Action Method from a Razor View

I know this is a pretty basic question over here. But could you tell me all possible options available to, call a Control Action Method [generally any server side routine] from a Razor View and, in what scenarios each are best applicable to be used in. Thanks. Answer Method 1 : Using jQuery Ajax Get … Read more

ContentPlaceHolder in Razor?

I can use ContentPlaceHolder’s with Webforms view engines to put stuff in different locations in the master page. How do I do that with Razor? <div id=”content”> <asp:ContentPlaceHolder ID=”MainContent” runat=”server”> </asp:ContentPlaceHolder> </div> <div id=”footer”> <asp:ContentPlaceHolder ID=”Footer” runat=”server”> </asp:ContentPlaceHolder> </div> Answer Yet again I managed to ask before finding the correct search keywords in Google. In … Read more

ASP.NET Web Api – Startup.cs doesn’t exist

I have an ASP.NET Web Api solution which doesn’t contain a Startup.cs class. I presume this is because the solution wasn’t created as an MVC solution. All the code for the startup is defined in the Global.asax.cs file as you can see below public class Global : HttpApplication { void Application_Start(object sender, EventArgs e) { … Read more

How do I compress a Json result from ASP.NET MVC with IIS 7.5

I’m having difficulty making IIS 7 correctly compress a Json result from ASP.NET MVC. I’ve enabled static and dynamic compression in IIS. I can verify with Fiddler that normal text/html and similar records are compressed. Viewing the request, the accept-encoding gzip header is present. The response has the mimetype “application/json”, but is not compressed. I’ve … Read more

Is Task.Run considered bad practice in an ASP .NET MVC Web Application?

Background We are currently developing a web application, which relies on ASP .NET MVC 5, Angular.JS 1.4, Web API 2 and Entity Framework 6. For scalability reasons, the web application heavility relies on the async/await pattern. Our domain requires some cpu-intensive calculations, which can takes some seconds (<10s). In the past some team members used … Read more

what is the difference between a view model and a data transfer object?

I’m basing this question on Fowler PoEAA. Given your familiarity with this text, aren’t the ViewModels used in ASP.NET MVC the same as DTOs? Why or why not? Thank you. Answer They serve a similar purpose (encapsulating data for another layer of the application) but they do it differently and for different reasons. The purpose … Read more