Ive got an aspx file on the root of web application MVC5 project. I can go from Mvc View to the aspx file but im stuck on going back to mvc view. How do i go back from button event in Aspx? Fyi, this is just an empty project as im trying to learn on MVC. So everything is left as it is. Default configuration. The only difference that ive made is add redirect to the aspx page inside Home controller ActionResult.
Folder Structure and redirect code.
p/s. If you are wondering why i used an aspx file inside my mvc, im trying to do dynamic rdlc reporting using reportviewer. Im not sure if it could be done using mvc view. As far as i know, razor engine could not use reportviewer and thats why i use an aspx file. Im probably wrong on this as im still very new in doing MVC. Tqvm in advanced.
Try this:-
First change your current code
public RedirectResult Report()
{
return Redirect("~/ReportWebForm.aspx");
}
And in your .aspx page, add
Response.Redirect("/Controller/Action")
Related
I want a tag that basically performs a post action on my razor page model including a parameter. Ideally I don't want to have a form around it and have the linking to the according action in the href="post-to-action"
in MVC I was always able to call a controller action without having a form around a button/ with the following:
Add an Admin
This doesn't work for razor pages im pretty sure. Im struggling to find an alternative in razor pages. Of course ajax is an option but I didn't find an alternative to make a post call in razor pages without having a around it.
Does anybody have a workaround without having to submit a form with javascript or something along those lines?
In asp.net core razor pages , you can redirect user to another page with parameter like :
<a asp-page="/pageName" asp-route-id="#Model.ID">redirect</a>
But that is a Get request , you can't used to post data . You stil need to post use form :
https://www.learnrazorpages.com/razor-pages/handler-methods
Or use js to collect data and send to another page using AJAX .
I have a web application with a contact page that is a web form. Since I can't use the _layout.cshtml as a layout in the Web Form, I was wondering if it is possible to pass the code the web form to a view. I looked over the internet about this but I couldn't find any suitable answer.
I think that, passing the asp.net code to pure html is "possible" but how do I pass the "btnSend_Click" event?
It is impossible. You have to generate new codes for View.
i want to create an ASP.NET website, what i want to do is to create a page lets name it the main page "main.aspx", not MVC or razor pages.
Then inside this page i control and render the other pages using paramter in the url named "method" for example as following :
main.aspx?method=register : so the register page or view rendered in the main page.
main.aspx?method=users : the users page or view rendered in the main page.
My question is, what it the right choice to do this in Visual studio 2017 ?
if web forms is the right one, what is the main page should be "Default.aspx" or another page ? where i should exactly get the "method" value ? where i should put the template or the view of the "register" for example? and what is the expected content to be inside it ?
It sounds like you want a Single Page Application type of site.
My question is, what it the right choice to do this in Visual studio 2017 ?
Sure it is, if you understand what you are building. Try creating a new ASP.NET Core project with the SPA template, and see if that is what you are looking for. If so, I would strongly suggest checking out the [ASP.NET SPA Documentation(https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/build-a-single-page-application-spa-with-aspnet-web-api-and-angularjs)..
If you use Webforms, the template that can wrap other pages is called a MasterPage.
You don't need to pass the page name through a querystring, though. You can accomplish that with the URL Rewrite module or with Routing, but neither is necessary. The MasterPage will wrap any page that uses it automatically.
Here's an overview:
ASP.NET Master Pages
https://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
I know this may sound stupid but I am not able to include a controller rendering in the default Sitecore 8.1 layout.
I've created a controller in my MVC project and a controller rendering assign to the HelloController index action into sitecore. In the Home page I've added the controller as the sample rendering was done initially.
Someone said here that "layout was still pointing to default aspx instead of cshtml which caused this issue" I don't know how to change this.
In logs I've got an error like this:
Rendering control {id} not found for '/sitecore/content/Home'. Item id: {id}, database: web.
but the rendering exist in web database.
I've even tried in the new Experience Editor and got the same error but this time on master database which is absurd since the element was created on master database.
The controller works as expected when I create my own layout and add the controller to the page.
The questions are:
Why I cannot add a controller rendering to the layout?
How can I change that the layout to point to cshtml instead of aspx?
Unfortunately all the sample layouts and renderings are written in ASP.net WebForms and not in ASP.net MVC.
You can’t mix MVC and WebForms components in one single http request
Please install this package in your solution and it will work.
http://ctorio.aquasonic.ch/content/2014/04/Sample-MVC-1.0.zip
To point a layout to a aspx, you need to change the path to the cshtml file. Default layout . Check below picture:
Is it possible to create a .cshtml file (Razor) and process it manually? I would like to link to a page that does not currently have a controller, yet display a .cshtml page as a result. How would this be possible?
Not sure if its what you need, but Microsoft recently added something like this to the ASP.Net product line where you could use just Razor marked up web pages, and funnily enough they called it ASP.Net Web Pages.
http://www.asp.net/web-pages