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.
Related
I've got an application written in ASP .NET Core 3.1 that uses Razor pages to display various content.
I have a kind of project details view, where the details of the project are shown like image, description, some fields but also a list of files of the project.
The files of the project I collect using the Graph API (using credentials stored in Configuration/Azure Key Vault) and currently I list them out in a flat list. I store the list of files in my model (in a list with a custom object, to include metadata for the file)
I would like to show the files with folders, so the user only sees the top level folders and files when he opens the page. When he clicks on a folder, the folder should "open" and the user should now see the contents of the this folder (with an option to navigate one level up again).
Honestly, I am not quite sure how to start. I don't want to reload the whole page when the user clicks on a folder and as far as I know there is nothing like an Update Panel in ASP .Net Core that lets me only update parts of a page.
I also programmed some other Reat.JS applications, I know I could create a very dynamic react app to display those files but I am not sure if there is a good way to integrate such a react component in my ASP .NET Core app and also I don't know how I would pass the credentials to this component.
Hope someone can point me in the right direction and give me some tips.
Yes, there is no Update Panel in ASP.NET core MVC, but that doesn't mean you cannot update individual parts of the page. You can use a View Component to render just the content of a folder. The following is a list of key things you need to do to implement it:
Add a MVC action to your controller that returns View Component.
Enclose the folder content in a container div of known id.
Attach JavaScript event listeners to subfolders
When the user clicks one subfolder the event listener uses the fetch API to call the MVC action.
The event listener sets innerHtml property of the container div to the HTML returned by the MVC action
Attach event listeners to subfolders of recent loaded content.
This approach doesn't require any JavaScript framework or library. It can be implemented with plain vanilla JavaScript.
Probably you will want to add fetch and promise polyfills.
Unfortunately, this question is fairly broad and is likely to result in it being closed. (I didn't vote to close it). The challenge with this question is that there are so many different ways to handle this sort of programming problem.
Using ajax is one very common way to handle this. Which then brings us to javascript libraries, and there are a bunch of choices. You mentioned react. That is one good choice. If react feels too heavy for you then give my answer here a read with regard to Vue. VueJs is extremely lightweight and can easily be used on a single page or on a group of pages. Vue may be a great solution for you.
The main thing to know is that there is no "right" answer to your question which is why unfortunately it's not a great fit for StackOverflow. Here we prefer questions that have definitive answers. And this one has none.
I'm relatively new to Umbraco (but have read through the docs), so I apologise in advance.
I have a partial view on a website that I want to make editable (e.g. using page properties in Umbraco admin). The properties for this partial view will remain consistent on every page it's on. Is there a way I can edit those properties in one place or is there a concept of a shared component? At the moment the alternative is going through every single page and setting the properties wherever the partial view is displayed, which isn't a great solution for the number of pages it will appear on.
I have looked around, but I haven't found anything that points me in the right direction. I'm using Umbraco 7.6.6, so I'm a little restricted in what I can do.
The Umbraco.com website has some great documentation on getting started and setting up Umbraco. Umbraco TV is great for getting up to speed quickly too.
This is a HUGE topic, which requires a conceptual explanation of how Umbraco works, and the documentation is the best place to start, but I'll try to summarise the relevant elements.
What you're looking for is a Document Type. Document Types represent the data used by Umbraco pages and are stored in the database.
You create a Document Type for your page with an accompanying Razor Template from inside Umbraco. When the page is rendered by Umbraco on the front-end the Razor view is loaded, it references the Document Type (Model) and inserts the data. The Razor views can be created from inside Umbraco or using Visual Studio. Naturally you can include partial views inside the Razor Template.
Once you've created your page(s) in the Umbraco back-end and accompanying Document Type(s), which includes Data Types (inputs - media pickers, URL pickers, text inputs, Etc.), these can reference what is called a Composite Document type which can be included\shared in more than one page, a Composite Document Type is where you'd include properties which need to appear in more than one page but which have different data, such as SEO properties.
For Global properties I tend to add these to the root or landing page, then reference it in the relevant Razor page using LinkQ, inserting the properties where and when I need them in the page. An example of this would be including something like the Google Analytics ID in the master page. A Composite Document Type wouldn't be need for that.
The Umbraco documentation on querying gives this example of getting all the Name (default properties) of each page found under the root node, which may help as a starting point for referencing Document Type properties.
// Get the children of the first content item found in the root
#foreach (var child in Umbraco.ContentAtRoot().First().Children) {
#child.Name
}
I am working on asp.net. There is a page tested on my localhost. This project is transferred to me by previous developer. The page is "localhost:4472/TblQualClients/List.aspx" and it is working fine, but I could not find this aspx file in any of my folders; and in another aspx document, I found there is a pointing to this page, but it is shown as "File 'TblQualClients/List.aspx' was not found".
Can anyone help with this? Thank you very much.
Your project uses Dynamic Data.
ASP.NET Dynamic Data lets you create extensible data-driven Web applications by inferring at run time the appearance and behavior of data entities from the database schema and deriving UI behavior from it.
Dynamic Data supports scaffolding, which is a way to automatically generate Web pages for each table in the database. Scaffolding lets you create a functional Web site for viewing and editing data based on the schema of the data. You can easily customize scaffolding elements or create new ones to override the default behavior.
You can also enable dynamic behavior in existing or new Web applications without using scaffolding. In that case, you specify how and when Dynamic Data should infer UI elements from the data source without using scaffolding for the entire Web site.
Taken from the MSD website:
http://msdn.microsoft.com/en-us/library/ee845452.aspx
Also, refer to this article to understand how it works:
http://blogs.msdn.com/b/scothu/archive/2008/06/23/how-to-add-dynamic-data-to-an-existing-web-site.aspx
I'm trying to switch my custom cms written in php into .net c#. I was thinking to use cms as a learning project. I'm going to use C#, NHibernate ORM layer, mssql, mvc3 and jquery.
I'm aware there are plenty of commercials or open source cms, but still I'm going to spend some of my free time trying to learn new technology working on project like this.
So, is there anyone out there who is willing to share some ideas on creating cms domain model, usefull link, ideas, etc.
Thanks
A really basic CMS consist of 3 elements:
one database table to hold your "pages". The table structure is "name" and "content"
a route to transform requests of type /cms/pagename to a fixed controller, the method called cms and pagename as a parameter
a embeddable html editor
Now, there are two ways your "page" can be invoked. It is either create mode or view/edit mode.
In "create" mode, the page is requested but it is not in the database yet (e.g. cms/announcement1). In this mode you create a view consisting of a html editor and upon submit, you persist the page to the database.
In "view" mode, the page is requested and is IS in the database. You perform any necessary rewriting (for example you rewrite internal links of the form [cms/pagename] to a fully routable http address) and render the content.
If the user is authorized to edit the page, you also show a "edit" button which then invokes the html editor with the page loaded and ready to be edited.
And that's it.
There are tons of additional elements (caching, different built-in page types, embedding images, youtubes, preformatted texts) etc. but all of them are optional and you can introduce new features when you have the core already implemented.
Once I wrote a simple CMS following the structure above, it was a part of a bigger solution and till now it's been sucesfully deployed several hundred times. An advantage of a custom CMS is that it can be really simple and easily maintanable.
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.