I have a question about how to create a partial view of an external page, for example, Google's in C# .NET Core.
What I want is like the iframe that loads an external page but the iframe is not allowed to be used in the company.
I already tried with
await Html.RenderPartial("_AuthorPartial");
and it didn't work for me
Related
I'm creating a new website application in asp.net. The landing page needs to have a button (or something similar) which the user can click to create a new instance of a webpage. Similar to how a Facebook user can create a new group/event or a StackOverflow user create a new question.
My website needs to be able to create multiple "events" from the landing page which can then be accessed from the landing page, each event should be a template populated with user details on creation.
Can someone please tell me how people refer to this technique of creating many instances of a webpage (event) from one template?
With ASP.NET Core MVC (using this as an example as you have an ASP.NET tag and your description doesn't specify a technology), you can create a template using a .cshtml file. If you are not familiar with these types of files (which are used within the ASP.NET framework), then I suggest a read of it here:
https://www.w3schools.com/asp/razor_syntax.asp
Roughly, it's a file with HTML content where you can easily embed .NET types (such as types from your Model) and .NET logic using "Razor syntax", so that your HTML file is modified appropriately (e.g. with queried data specific to your user) before being sent back to the client. The reference above gives good examples, so I'm not going to waste space and repeat them here.
You can have certain .cshtml files as your "template" and embed appropriate model data using Razor syntax. You can then have a hyperlink tag (for example) reference the .cshtml file using the asp-action attribute. This will render the .cshtml file to the client whenever that tag is clicked on. ASP.NET uses types called Controllers to handle such requests (Controllers are types that inherit from the Controller type) appropriately, such as querying the correct database and providing your .cshtml file with the correct data before sending the result back to the client.
ASP.NET Core MVC modularizes the types of actions described above very well (M --> Model, V --> View, C --> Controller). Here is a good reference:
https://learn.microsoft.com/en-us/aspnet/core/mvc/overview?view=aspnetcore-2.2
For other technologies that you wish to use to achieve the same result, you will have to consult the appropriate references.
Stackoverflow is a place to get answer on specific problem with short answer. Your problem is general design and programming question, and requires understanding of basic programming aproaches.
For that you should grab a book and read about designing webapplications in .Net.
I am new to ASP.net MVC web development. I created the default MVC application! In the top of the Home page You find Home,About and contact buttons.
But When I checked the index.cshtml I can not find the code for Home,About and contact buttons!
I searched other files in the solution but was very hard to locate them! In which file can I find the code for these buttons?
yes..kushan....that is why it is suggested in mvc that to start with
empty mvc application
instead of going for the ready made template ..
Because by manually creating each part you would learn the use of layout , partialview , how to add scripts & webconfig , startup.cs etc
anyways the corresponding code for your landing page
could be found in the respective controller & views folder
Your looking for asp.net-mvc Layouts.
Excerpt:
Most web apps have a common layout that provides the user with a consistent experience as they navigate from page to page. The layout typically includes common user interface elements such as the app header, navigation or menu elements, and footer.
While adding view to your project it show option to include layout page,
ADD LAYOUT PAGE.
By default c# mvc application contains layout.cshtml page which contain your about, home etc links.
So by enabling layout.cshtml to your page help you out.
If you want to add it manually then create anchor tag to your page which contain 'href' that contain links.Also make methods in controller to handle link clicks.
You can also add your own layout.cshtml page which contain link to your home,about, contact us etc and refer layout.cshml to every other cshtml page.
Again, I've looked around to try to find some posts on this and there are many but none that address my specific question (that I could find).
What I am looking : I have a projects and it loads different pages (.aspx) in an iframe dynamically. Now I am trying to remove iframe and add a div and load aspx pages inside that div, using this :
$("#containerDiv").load("test/default.aspx", function () {
});
it loads aspx page easily but I am unable to execute C# code which is written in default.aspx.cs may be its not a good practice but I want to know is there any solution of my problem.
$.load will not your c# code why because it load only the contents of your aspx page not of aspx.cs.
Use user controls instead.
If need help how to implement user control refer this link.
I've built a pretty simple content manager for a website that I have. For every page, the user has control over what content is displayed by using an Admin tool.
Now, my client wants the ability to add entire pages. Right now, I have to create a new page, and then they can go in and edit the content for that page. But they don't want to do that anymore, they'd like to create their own without having to come to me. They'd like the name of the page to be consistent as well - so if they create an "About" page, it would be mysite.com/about instead of mysite.com/dynamicpage/8.
I need to be able to do this without using a third party CMS, considering that there already a robust Admin backend. Is there any tutorial about how to do this?
I'm using ASP.NET MVC 2, .NET 4.0.
A simple solution here (and you should probably customize it a bit):
Simply create a route that contains a variable (say pageName or something) on a ContentController or something. AKA (mysite.com/content/{pageName}). Your action method takes the page name, and then loads up the HTML via the database. It then simply returns that HTML as a Content Response
return new ContentResult
{
Content = htmlFromDatabase,
ContentType = "text/html" // Change if you want depending on DB values
};
Then you just need one admin panel to update the DB entries with content and the client can add / remove / edit entries that just exist in the DB.
While I haven't tried it you can have a look here http://haacked.com/archive/2009/04/22/scripted-db-views.aspx
And it has already been asked and answered in SO Create Dynamic pages in asp.net mvc
If you can move to MVC3, you can use Razor's ability to execute scripts (pages) from a string.
I'm using this open-source project to do something very similar.
Then, all you need to add is a page in your admin area to edit the virtual pages, and stuff the result into a database.
Your controller will examine the requested route and retrieve the correct page record from your database, use Razor to execute the page (and get the result as a string), and send the result back to the client.
This will let you easily include dynamic content within the page (the script can, say reference partial views that return the dynamic items). If all they need to do is edit HTML, it's probably overkill.
I need to be able to load web pages from different sites within a page on my site. I am using C# .NET and master pages. Within the content page, I want to be able to load an arbitrary page and display it without any of the browser controls appearing - just the page content.
Can you not just use a boring old iframe?
<iframe src="http://stackoverflow.com" width="900" height="500"></iframe>