Creating a Basic MVC Project with Unit Tests in Visual Studio 2010 - asp.net-mvc

I wanted to set up an MVC 2 web application in Visual Studio 2010 using C# as the language. For that, I referred the link: http://msdn.microsoft.com/en-us/library/dd410597.aspx and I created the same. When I ran the application by pressing F5, I got an error in my browser. I have attached the error information below.
Please help me to resolve this.

MVC is different from regular ASP.NET. In MVC you are using the http-address to tell your application which method to fire in which class.
In MVC language methods are called "Actions". And classes are called "Controllers" (ruffly speaking).
If you want the first view to show, you will have to tell the class "HomeController" to perform its method "Index()".
You do this by entering the address: "localhost/Home/Index"
Please read more here:
http://msdn.microsoft.com/en-us/library/dd410269(VS.98).aspx

If your controller is called MapsController with an ViewMaps action as shown in the tutorial then you should navigate to /maps/viewmaps in your browser to execute this action.

Related

Visual Studio 2015 - Debug ASP.NET MVC source code immediately on POST

I'm having a problem with the default model binder being slow in my ASP.NET MVC web application on a specific controller. I'm looking to basically debug immediately when I hit the POST and see the ASP.NET MVC source code that is fired first (the model binder, etc.) before my controller's code.
How can I do this? I thought this should be an easy task but Google isn't turning anything up. I'm using Visual Studio 2015.
To debug ASP.NET MVC source code, it was related some debugging options under TOOLS->Options->Debugging.
It also was related to the Microsoft Symbols Server under TOOLS->Options->Debugging->Symbols.
So if you want to debug MVC source code or not, please enable/disable them, view the results.
Reference:
https://weblogs.asp.net/gunnarpeipman/stepping-into-asp-net-mvc-source-code-with-visual-studio-debugger

Using the razor engine in SharePoint 2013 Visual Web Part

I'm trying to make use of the razor engine in a SharePoint 2013 Web Part. This, I read, shouldn't be too difficult since SharePoint 2013 Visual Web Parts can be built using .NET Framework 4.0
I'm simply not sure of where to begin to do this. I've seen an article on uploading the .cshtml file onto a document library and referencing the document library in the Web Part, but it is a bit unclear.
Does anyone have an idea of how I can start? Or point me to a step-by-step guide to achieve what I am after.
What my end goal is: Take a piece of an MVC application, customize it and make it a Web Part. I need to be able to modify or access SharePoint content on that site which is why I cannot use an App Part.
Okay.
First install the Office Development Templates from
http://www.microsoft.com/visualstudio/eng/office-dev-tools-for-visual-studio
This will give you the following template selection on reopening Studio
Then navigate to wherever EwsManagedApi32.msi is and enter the following command in an elevated prompt -
EwsManagedApi32.msi addlocal="ExchangeWebServicesApi_Feature,ExchangeWebServicesApi_Gac"
Now your templates are usable and the one you want is "VS2012 Web Part".
Now, by default this will add an ASP.NET project, which is not what you want, so manually delete the ASP.NET project, add an MVC one, highlight the SharePoint project in Solution Explorer, hit F4, and select the MVC project in the "Web Project" dropdown at the bottom of the properties.
And there you go. One controller per web part, sorted.
I am sharing link SharePoint MVC webpart that uses Knock out framework using MVC for SharePoint. It has step by step instructions which might help you.
Hope this will be a good starting point
http://www.codeproject.com/Tips/739445/SharePoint-Razor-View-WebPart

How to open MVC 4 view page from webform.aspx page?

basically i am looking for something like this ,
i got webform.aspx page and have button there, if i click on it i need to show MVC view page
idea is i want app with webform and mvc !
what i am trying is :
http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc
but here i am confused about webconfig settings
please help me to get it done,
thanks
Scott Hanselman has a good guide on integrating MVC with a Web Form App, it should take you through the steps, here it is in a nutshell:
Run the Upgrade Wizard (open the Visual Studio2008 Web Application
in Visual Studio 2010)
Create a default ASP.NET MVC application for reference (you'll throw it away later)
Use a differencing tool like Beyond Compare to integrate the new web.config entries from the ASP.NET MVC sections into the upgraded ASP.NET WebForms application

SinglePageApplication - match sample videos from 2012 Fall update

I am trying to recreate the ASP.NET Single Page application as demonstrated by Steven Sanderson
Single Page Applications - for desktop, mobile, tablet with ASP.NET MVC4
I have downloaded and installed the Build Preview - http://www.asp.net/vnext
I have using NuGet, tried to update my SPA Scaffolding to ASP.NET SPA MVC 4 (Beta)
I am running Visual Studio 2012
When i create a new MVC4 application, there are some distinctive differences between what i have and the demo's i see.
Primarily, after create a new project, if you view what you have the sites look completely difference
What Steve Sanderson Gets
What I Get
Then continuing to follow his example, he created a controller and has an option of
Single Page Application with read/write actions and views, using Entity Framework
This is not avaiable in my Create Controller Dialog
What Steve Sanderson Gets
What I Get
Why are my options differen't?
What have I not installed?
Thanks for any help
The new SPA template is a completely different template, as you have discovered. Short story ... the new template is revised to be a starting place, the old template was deemed too prescriptive.
The new template is a preview and will have more changes by the time it is released. The idea is you can use it as a starting point for a SPA and then add features and other libraries as needed.
UPDATE: If you want more info on what's in the latest template you can read my post here: http://www.johnpapa.net/insidespatemplate

Console App CSHTML Intellisense and Binding?

I have a console app without a project reference to any ASP.NET MVC App. Running Visual Studio 2010.
I created a cshtml file to test some template binding. I am not getting IntelliSense in the cshtml and putting "#model MyDataClass" at the beginning of the page is not getting recognized either.
How can get some View functionality in my console app?
Thanks.
Follow instructions in this blog post - https://blogs.msdn.microsoft.com/webdev/2011/01/20/how-to-get-razor-intellisense-for-model-in-a-class-library-project/
Also, add references to System.Web.Razor.dll and System.Web.WebPages.Razor.dll
Try using RazorEngine it allows you to use Razor templating in Console applications.

Resources