ASP.Net MVC View within WebForms Application - asp.net

I am adding functionality to an ASP.Net webforms application and we've decided that new development will be done MVC with a view to move all functionality over eventually.
Obviously, MVC and WebForms play together rather nicely when it comes to accessing an MVC action via a URL. However, I'd like to display the MVC view within an existing tab (telerik) control on a WebForm page. This view will be using js/css file so that will need to be considered also.

Well I'd use jquery/js to load the tab dynamically on page load / select tab. If add a js function to the required handler you can fire an ajaxGet to retrieve the html from your MVC action URL.
If needed I can get some sample code. Are you using jQuery in your ASP.Net app or MSAJAX ??
Cheers
ian

Related

ASP.NET MVC Change View Engine in existing project - From Razor to ASPX

There are few posts about changing ASP .NET view engine from ASPX to Razor.
However, I have a business need where I need to change my view engine from Razor to ASPX because we are using enterprise frameworks controls that only render pages in ASPX view engine. How do I do this?
I understand that it's trivial when we are setting up the project but this is an existing project. I have tried the following in Global.asax.cs but its does not have an option to add ASPX view engine, am I missing something here?
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine()); // no ASPX view engine option?
Any other way we can change View Engine from Razor to ASPX for an existing project? Otherwise, I have to create a new solution using ASPX as view engine and port all the codes, super unproductive.
You can add the Web Forms view engine using:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngine());
You can even have both view engines in a single project if you don't want to rewrite any existing Razor views using the Web Froms engine.

Same Component in both asp.net, asp.net MVC and Classic ASP

I have a big website/application coded in Classic ASP, ASP.NET and ASP.NET MVC.
I have a menu on top with a lot of HTML CSS JS, and some conifiguration (visible or not ...)
and lot of dynamic links.
So the problem is when i have to update the menu i have to update 3 files, one Include in Classic ASP, one ASCX user control in asp.net and one Partial view in asp.NET MVC
I hate code duplication, so is it possible to use only one component ?
I heared about Com but i have no idea where to start.
Thanks for help
Edit : I am thinking know to use a .net Object, that can generate a string containing all the html that i need and then put it in the views MVC and in the asp.net pages
But how to use it in Classic ASP?
There's nothing stopping you using a webapi controller to expose this functionality; the webapi controller would return json or xml menu structure to the client browser this in turn would be rendered using by injection of the json over into the browser DOM and styled using CSS.
Classic ASP and MVC ASP.NET would use the same javascript and css.
I'm also working in a legacy application that is very much similar to your case, how bad the life is :(
I'll go for XML/XSLT in your case.
I'll create an XML file that contains all the menu details and use XSLT to generate HTML from XML. I can easily use the XML and XSLT in all the three technologies. So every time you need a change you have to change either the XML or XSLT file.
You can even create a simple .NET component that uses the XML/XSLT approach which could be easily used in ASP.NET Web Forms, ASP.NET MVC (in custom view engine?) and in classic asp as well (you have to register).
Guess, you can make an action method in asp.net MVC to render the dynamic menu and do AJAX load from the javascript in every part of the site?
UPDATE:
You can make an HTTP GET request in classic ASP to the aforementioned ASP.NET MVC handler, and cache results if its not very dynamic. Anyway it should be pretty fast if its within the same server. I suppose, request will look like in this answer

Link to aspx page from asp.net mvc project

I have asp.net mvc project with razor views and i have in the same solution another project that is rendering (aspx) pages (reports and stuff) so i don't know how to call that page or show it inside view. i have tryed with render action and link but it just can't be found.
It's just one aspx page inside other project so i have path like: /projectName/page.aspx
Any help would save my day
If you have two web projects I suppose they have two iis mapping.
So calling from a site to another site you use href link, to render a page from another site the only thing I can think of is using iframe.

Sending asynchronous request on clicking a sharepoint web part button control

I am new to this whole sharepoint and aspx programming. I have developed a sharepoint web part that has a button control. The onclick event is mapped to a method in my web part code. When I click the button the whole page reloads and the web part is rendered again. Is there a way to prevent this reloading of the page? Is there a way to call the function method in the background? Something similar to AJAX.
Thanks,
Jagannath
You can use Ajax, it just requires some sharepoint configuration. Here are a few posts to get you started:
http://weblogs.asp.net/jan/archive/2007/02/26/using-the-ajax-control-toolkit-in-sharepoint.aspx
http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3
Ajax or SilverLight are your only two options for Async operations without a page refresh.
Once you know the tricks needed to get SharePoint and ASP.NET AJAX to work together it's not that difficult.
Here are the steps required:
Ensure the ASP.NET AJAX Extensions are installed on all the front-end web servers (this is not required if you are using .NET 3.5 as the Extensions are included in the Framework)
Update the Web.config file for the SharePoint Application to support ASP.NET AJAX
Ensure any page that is going to use AJAX has a ScriptManager
Use an UpdatePanel or a client-side service call to get updated data and re-render the Web Part
This blog post has some resources from a talk I did on the subject at TechEd Barcelona 2008. These resources should give you the information you need to get started.
http://msmvps.com/blogs/windsor/archive/2008/11/13/teched-emea-resources-and-demos-integrating-asp-net-ajax-with-sharepoint-2007.aspx

ASP.NET Ajax feature in existing ASP.NET website

I have a ASP.NET Website which was developed in ASP.NET 2.0.
Now I want to add a new page to the project which will make use of the ASP.NET AJAX features like Partial page updating.
Is there any options to do this ? Do i need to change any settings for this in my already existing project /Solution ?
The only problems you may run across is inside you web.config file if you don't go in and register the asp.net ajax assemblies.
Other than that you should be able to add a scriptmanager control and work with the page like any other asp.net ajax page.
Edit: Here is some documentation that should help you configure ASP.NET AJAX to an existing website.
http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx
There is a great tutorial about how to implement AJAX on a regular ASP.NET web site.
http://www.asp.net/learn/ajax-videos/video-81.aspx
Hth...

Resources