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:
Related
I have build an web application, and I want to delete some record in the database using ASP.NET MVC. But, in the delete Razor View, the CSS is not working, so the page is like this 1. This is the Delete Page of my application 2. I wonder if there are any solutions for this problem. Thank you in advance.
Check this document describe col-sm, and as i notice the CSS classes that you have been used were marked with red, so maybe the version of bootstrap doesn't contain those classes.
the reference:
https://www.w3schools.com/bootstrap/bootstrap_grid_examples.asp
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 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
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
I am converting an Forms based application to add some MVC 4 View Pages.
I have been able to get pages to work but when I create a view, it never looks in my Views/Shared folder and requires me to put the shared page inside the same view folder instead of defaulting to Shared layout if not specified.
Where is the routing information precedence in MVC4 stored so I configure it to look in the shared folder first? In a slightly related question, is there any way to get the Add Contoller wizard option to show up when right clicking on the Controllers folder and the Wizard to for the scaffolding views? (See picture below of add wizard for example)
Update: After some frustrating time I have added the file into the path desired by the error message and I still getting the error message. It seems the routing is working because when I return a string, the route finds and displays it. The problem appears to happen when I use an ActionResult and for some reason cannot find the "associated" files.
In your _ViewStart.cshtml file in your Views folder, you should have something like:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
That's what tells it where to look for the layout.