How to show webforms page .aspx in VIEW MVC3 Razor - asp.net-mvc-3

My project developed in MVC3 Razor Tech. My master page and content page are developed with Razor MVC3. I want to show a SSRS report builder on my project. I searched in blogs and come to know that we can't show the SSRS reports in MVC3 Razor.
Since We can used 'webform' in MVC3 we can show the report.
Problems: In my project both master and content page are all developed with Razor .cshtml Since accessing .aspx is difficult.Correct me if I'm wrong.
Requirement: Please help me to show the webforms in the 'VIEW' MVC3 Razor framwork.i.e My project landing page is the webform. In that webform page I need to show the SSRS report

I had to do it and so I worked for me :
Suppose you have a controller called Summary .
For this implementation, You don't need to add or modify any of the actions that you have.
Then, as you told me, you add a file named "SkillReport.aspx" in your views folder
Views/Summary/SkillReport.aspx
( initially left in blank SkillReport.aspx or just add some text like "Skill report" )
In Global.asax :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Report", "Report/{rptController}/{rptName}", "~/Views/{rptController}/{rptName}.aspx");
...
}
****--> I have attached the snapshot of my solution explorer
My routes.Mappageroute code is
"routes.MapPageRoute("Report", "Report/Summary", "~/Views/Summary/SkillReport.aspx");"
Please change the mapPageRoute for the above folder structure.** <--
The values ​​enclosed in {} are placeholders. You must not give the name of the controller or report there. When a request is received, this route determines which controller to invoke by adding the suffix "rptController" to the controller value in the URL to determine the type name of the controller that will handle the request. The rptName value in the URL determines which WebForm.aspx to call.
Suppose you need other two reports.
In Summary controller, and report name FullNames
In a controller named Product, and report name List.
Using the parameters you avoid having to create a route for each report.
routes.MapPageRoute("Report", "Report/{rptController}/{rptName}", "~/Views/{rptController}/{rptName}.aspx");
http://localhost/Report/Summary/SkillReport --> /Views/Summary/SkillReport.aspx
http://localhost/Report/Summary/FullNames --> /Views/Summary/FullNames.aspx
http://localhost/Report/Product/List --> /Views/Product/List.aspx
On this route we added:
"Report" is the name of this route, you can put any other
"Report/{rptController}/{rptName}" : This is the pattern URL to identify
when to invoke your Report-WebForm, "Report" works as "key" and
{rptController} is the name of the controller. rptController will be assigned with the Controller name. In this case Summary and rptName with SkillReport
"~/Views/{rptController}/{rptName}.aspx" is the physical
path. When using this route with Summary controller, and call SkillReport this will
invoke to Views/Summary/SkillReport.aspx
Routing documentation: http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx#url_patterns
At this point you can verify that you can access your SkillReport.aspx in your development environment using :
http://localhost/Report/Summary/SkillReport
Or maybe at some particular port... like
http://localhost:1057/Report/Summary/SkillReport
Finally, SkillReport.aspx (like this... check ProcessingMode...)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="SkillReport.aspx.cs" Inherits="XXX.SkillReport" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=100"/>
</head>
<body>
<form id="frmRpt" runat="server">
<div>
<asp:ScriptManager ID="sm" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="rpt" runat="server" Width="100%" Height="90%" AsyncRendering="false" ProcessingMode="Local" ShowRefreshButton="false">
</rsweb:ReportViewer>
</div>
</form>
</body>
</html>
With this tag
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
you achieve that show in Safari and other browsers.
To access the report from a VIEW (.cshtml) need to add a link. i. e. :
<a href="/Report/Summary/SkillReport" >Show My Report :) </a>
As a last comment, I recommend that after creating SkillReport.aspx enter in "Design Mode" and drag from the toolbox the Reporting's controls. This will automatically register the required values ​​in web.config

Answer #1 was useful:
Just make sure that your order of MapRoutes is in the right order of precedence:
e.g.:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
routeName: "Report/",
routeUrl: "Report/{rptController}/{rptName}",
physicalFile: "~/Views/{rptController}/{rptName}.aspx"
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

Although this would not be a recommended practice it is doable. I'm copying a link that shows you how to use two View Engines in the same project.
http://weblogs.asp.net/gunnarpeipman/archive/2010/07/29/asp-net-mvc-3-using-multiple-view-engines-in-same-project.aspx
Let me know if this works for you.
Update:
This might be of help as well, another option looks like registering a route for your aspx page.
[StackOverflow Post] Aspx page in MVC3

Related

Display external application forms within Microsoft Dynamics 365

We have our own system which we need to integrate with MS Dynamics 365.For Example : In Accounts section we need to add an extra tab that loads IFrame or something that retrieves some extra information from our system.
The following are the things that I reached :
Inserting IFrame within a new Dashboard: (but it will not fetch specific account information, it will only pass the currently logged in user along with the organization name)
Unified Service Desk (USD): (we may add customization but this is a desktop app and we need it to be on web)
Microsoft flow: this would only work in the background when you create or edit an account (not sure if it has another functionality)
Extensions: Not sure how to use it to achieve the same functionality, I believe the solution may be here but I just need from where to start.
Has anybody done a similar thing before?
Thank you
You can definitely do it,
Here is how I just tried on one of my Trail Instance.
I added new Tab as you need, I called it "HTML Page"
On this Tab I added Webresource, you can add Iframe as well and call your external WebPage.
For my simple use case I created a simple HTML page as webresource in CRM and configured it to Webresource tab as below
Sample code for HTML. Dont worry about long html file. Mostly it is bla bla. What is of our importance is <body onload="myFunction()"> and then in
<script>
function myFunction() {
debugger;
alert("Account Id when from fromcontext is ");
alert(parent.Xrm.getformContext().data.entity.getId());
}
</script>
complete HTML code below
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My first styled page</title>
</head>
<body onload="myFunction()">
<!-- Site navigation menu -->
<ul class="navbar">
<li>Home page
<li>Musings
<li>My town
<li>Links
</ul>
<!-- Main content -->
<h1>My first styled page</h1>
<p>Welcome to my styled page!
<p>It lacks images, but at least it has style.
And it has links, even if they don't go
anywhere…
<p>There should be more here, but I don't know
what yet.
<!-- Sign and date the page, it's only polite! -->
<address>Made 5 April 2004<br>
by myself.</address>
<script>
function myFunction() {
debugger;
alert("Account Id when from fromcontext is ", parent.Xrm.getformContext().data.entity.getId());
}
</script>
</body>
</html>
Also on Form Load of account I added additional Javascript. This javascript will create global variable which could be called from your webresource.
Article Link for additional Javascript
Sample code used for Javascript below
formContext=null;
function onload(executionContext){
debugger;
var formContext = executionContext.getFormContext();
Xrm.getformContext = function (){
return formContext;
};
Xrm.getParentAttribute = function (attrName) {
debugger;
return formContext.getAttribute(attrName);
};
Xrm.getParentControl = function (attrName) {
debugger;
return formContext.getControl(attrName);
};
}
Final Result will be something like below
Summary:
Create Wberesource/Iframe
Create Additiona Js on Load
Use global variable in your webresource.

Pass selected element from list group Thymeleaf

I am using Thymeleaf and Spring MVC for a project and I am displaying a list in Thymeleaf and I want to get the selected items and pass them when I press submit
This is my form with the list:
<form th:action="#{/trip-info}" th:object="${trip}" method="post">
....
<a class="list-group-item list-group-item-action" th:each="currentPerson : ${trip.employees}" th:text="${currentPerson.getFirstName() + ' ' + currentPerson.getLastName()}" onclick="addPerson(this)"></a>
</form>
I have the employees list displayed in my page, now I am not sure if I can pass to a controller the selected values or if I must use javascript and construct a body. Does anybody have any ideas ?
Thanks!
Transferring the selected form item is outside the role of 'Thymeleaf'.
'Thymeleaf' is a server side template engine that simply creates code in html.
The event (item select) changed by the client must be processed by JavaScript.
For a simple example,
Before submitting from the form, check the selected item in javascript and create a function that performs the submit.
If you need an example, show me your source code in more detail.
Additional comments -
There are two ways.
1. How does 'a tag' directly tell you about your event?
2. How to externally liseten events of 'a tag'
I wanted the '2' method, and you chose the '1' method.
Your source will be terminated with the href moved before executing the 'onclick' event.
Take a look at this example.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
some method<br/>
some method2<br/>
some method3<br/>
<script>
function someEvent(event){
console.log(event);
}
</script>
</body>
</html>
'href' works but is invalidated by void (0). Or moved to another window tab by target. And then onclick happens sequentially.
I can not speak English and the explanation is immature. I'm sorry.

How to Return a View from a Controller to an iFrame

I am new to MVC 3 and have come accross the following scenario:
First let me explain how I have setup my application:
All post backs to the server use jquery ajax which which return a view from the controller that either appended or prepended or replace a targeted div.
The Scenario:
I have come to a point where I would like to upload images but unfortunately because of the jquery ajax posting I cannot get the values for an html in C# Request.Files. I know there are plugins out there to help out with this but I would like to do this myself so I have created an <iframe> which i then use a bit of javascript and post the form targeted to the iframe (old classic way of doing things):
function UploadImg(SACTION) {
alert(SACTION);
validatorform.action = SACTION;
validatorform.target = "fraImage";
validatorform.method = "POST";
validatorform.submit();
}
the SACTION parameter looks like this #Url.Action("UploadFile", "Response"). This all works well as it hits the controllers action method and I can then save the image:
[HttpPost]
public ActionResult UploadFile(string ArticleID)
{
ViewBag.PreviewImage = cFileUploads.UploadFile(ArticleID, Request.Files[0]);
return View("ImagePreview");
}
I would now like to return a view to the iframe (simply to preview the image and then do a couple of other things but this is besides the point)
The View for previewing the Image:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="">
<img alt="" src="#ViewBag.PreviewImage" />
</form>
</body>
</html>
The Problem:
Unfortunately when I return the View (ImagePreview.cshtml) in C# the whole page is refreshed, all I want is for the iFrame to be refreshed. How should I return the view from the controller?
Fiqured out the problem, I had a bit of javascript that was replacing the contents of a div that the iframe was sitting in ... (slap on my forehead). All working perfectly now :)
Will leave this question here just incase ..

asp.net mvc 3, add <meta /> to <header> from any part of application

My question is: How can I add meta tag from my view or partial view? Basically I want to, from the view, write a meta tag, and I want it to be displayed in the header. Is it possible?
Thank you
H
You can use sections to do this.
In you layout page you need to define the section:
<head>
#RenderSection("Head", required: false)
</head>
This section can then be used in any page that uses this layout page:
#section Head {
<meta ... >
}

meta tag in ASP.NET MVC 3

How can I put meta tag to work only for one page. If I want to put it .aspx file, where is right place.
Thanks.
Since you haven't said yet, I'm assuming you're using the Razor engine (the "default" for new MVC3 projects). In that case, you just need to insert a new section into your layout view, and only render that section if you need to insert a meta tag.
For example, working from the stock New ASP.NET MVC 3 Project template, you would edit your Views\Shared\_Layout.cshtml file, and before the closing </head> tag, do something like this:
#this.RenderSection("MetaContent", false)
</head>
Then, in any of your views that you needed to, add this:
#section MetaContent
{
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
}
If you're still using the ASPX layout engine for some reason, you can accomplish the same thing using the <asp:ContentPlaceHolder> tags in your master page and <asp:Content> tags in your views.
EDIT:
Since you're using the ASP.NET Forms layout engine still, here's the same basic idea as above in aspx syntax:
In your master page, you add the tag:
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
</head>
And in your .aspx views, you add a new content section (you should already have at least two -- a title and a body):
<asp:Content ID="Meta" ContentPlaceHolderID="MetaContent" runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
</asp:Content>
I was going to suggest exactly what Michael said (+1). Another option would be to put a boolean in the ViewBag, something like:
ViewBag.ForceIE8Mode = true;
For pages that you want to force into IE8 Mode.
and then in your view, wrap the meta tag in a conditional. either
#if(ViewBag.ForceIE8Mode == true) {
<meta... />
}
or
<% if(ViewBag.ForceIE8Mode == true) { %>
<meta... />
<% } %>

Resources