Create new view through code - asp.net

Is it possible to add a new view from code that can be executed on a button click? In stack overflow, a new view is generated when we post a question. Is is possible to do this in ASP.NET MVC5?

It is not possible to create a new view from code. But why do you need it. I guess to provide a different URL to each table entry so that it indexes better. For that you can change the URL of your details view.

Related

ASP.NET Core - Fill a form inside a View with bound ViewModel

my question is more logical than practical. So I have notifications system and everytime a notification is clicked it reroutes me to a page where I should give feedback to a user.Example
I need the UserId inside my Feedback Page, this way I can add the new Feedback to that user.
So what I am asking is: How do I tackle this problem? Will ViewData[] solve my problem or is flawed this way.
Since you are rerouting to a new page, and want to pass in the user's ID, I believe you would be well off to use a Query String
From the link that takes you to the Feedback Page, you can use a URL like this:
https://example.com/feedback?userId=123456
or add it to however you are building your links
From the Feedback Page, you can then capture that query from the URL

Search functionality in asp.net

I'm learning to create a webapp using asp.net and C#. And I already create a basic user database webapp. Wherein I display all the user information in a tabled manner. So basically I just used the table element from HTML and not the gridview control.
But I have a problem right now, I want to add a user search functionality wherein I will just input the user's firstname in the search box, so then when I click the search button it will display the user information in a table format. So I don't know how to implement it because I used the table element not the gridview. Where to I write the data that I searched?
Please advise.
Many thanks
It doesn't matter what you use to display the results, you can reuse that code. The only thing you need to change is the way you select the data from the database based on the firstname.

Views page and AJAX

I created a page view where it lists all nodes grouped by content types. My problem is how to create a page which will only output the view, I mean without the headers, sidebars etc.. just the view content? My reason for doing this is I would later call the view / view page in an AJAX request and display to the user.
My view name is 'node_list', and I used the files views-view-list--node-list.tpl.php and views-view-fields--node-list--page.tpl.php to theme the output. But I have no idea how to create a page with only the view visible..
I hope you can help me. Thanks!
The easiest thing, is to create the call back for the ajax function and just return the view you want to insert using views_embed_view

I have a need to give the users the ability to update a dropdown and apply that to their submission

I have an application that I am writing in ASP.NET MVC 2 following the Nerd Dinner tutorial. I am very much a beginner and was looking for examples/tutorials I could follow that would enable me to learn how to code the following scenario:
A user has the option to select an option from a dropdown.
If the option is not there then they can enter a new option and add it to the database and list in the dropdown.
I would like this to be done without the user leaving the page and what they have entered so far.
I am using a simple Entity Framework 4.0 model which I have built a repository on top of so I have methods I can call to save the filled in user information.
If the entry already exists in the database then I would like to offer the user the chance to either select that entry or to continue adding the entry they request because it can be a list of names and of course you can have more than one person with the same name.
I have implemeted this and it follows the following workflow:
1) Provide a button next to the select list to add items
2) Populate the drop-downlist when the page loads
3) When the add button is clicked, implement the UI as you like, we use a jquery dialog box.
4) Post the value to a view (via jQuery Ajax) The view should return a JsonResult
5) Check to see if the item exists, get existing id if exists or add and get new id
6) Returns a JsonResult that contains the new list and the id
7) In the reply to the ajax post, repopulate the select list using jquery and select the item.
HTH

How to make rich/compound views

I have recently started to examine ASP.NET MVC. I have studied quite a few examples and common to these are that they contain quite simple scenarios, where a view will map to either an instance of a type in the model or a list of a paritcular type from the model.
I'm looking for guidelines to compose/composite views. In the long term I would like Ajax to be part of the equation, but for now I'm looking for a simpler non Ajax setup.
The problem
Here is a description of a contrieved problem. A domain model contains the types A and B.
class A
{ String ID, String Name, int Age
List<B> ListOfB
}
class B
{ String ID, String Name, String Url}
I would like to have a that allows the following:
A DropDownList showing type A information
Details about the particular A picked in the dropdown
A list showing type B's related to the selected type A
A form that makes it possible to edit the data of a selected type A
A form that enables the user to add a new B.
The view should not show all of this at once, instead it has to show different combinations of information and functionality according to user input. Combinations of detail and functionality could forexample be:
Initially only show the dropdownlist containing A's
If an A has been selected in the dropdown:
Show the particular A as selected in the dropdown
Show detail info about the selected A
Show list of detail info of related type B's
The user wants to edit a particular A
Show the particular A as selected in the dropdown
Show form that allows user to edit particular A
Show list of detail info of related type B's
The user wants to add a new B
Show the particular A as selected in the dropdown
Show detail info about the selected A
Show list of detail info of related type B's
That could look something like this (used the web version of balsamiq mockups - what a fantastic invention!):
Combination 2:
Combination 4:
Creating the view and controller
Since the solution has to allow for different combinations of data and functionality, I think it would be smart to have a parent view (not to be confused with a masterpage) that contained placeholders for parital views. Then, the parent views controller could make up the right combinations of model data and partial views and feed these to the parent view.
Finally; the questions:
Is my way of thinking in accordance with the asp.net mvc methodology?
Can you explain/show (not necessarily all of it) how the controller can compile the right combination of partial views and feed these to the parent view?
Can you point me towards an Ajax based solution?
Can you suggest books/links that contain examples of complex views?
asp.net mvc fully supports all of your requirements but there are few things you should get up to speed on:
You should look at implementing view models to help seperate your domain model from your specific views. Here is a good link on how to start this.
You need to get up to speed with a client side javascript framework for the ajax work with partial html rendering. jquery will do this or ms ajax. Here is an example
To your detailed questions:
Is my way of thinking in accordance with the asp.net mvc methodology?
Asp.net mvc is not going to constrain you at all so essentially this is fully supported
Can you explain/show (not necessarily all of it) how the controller can compile the right combination of partial views and feed these to the parent view?
You can use partial views if you want to seperate bits of code out and can easily refresh them by loading them independently using ms ajax or jquery. You would have a controller that mapped onto your parent view and can delegate and refresh partial views in ajax calls.
Can you point me towards an Ajax based solution?
jquery will do this or ms ajax. Here is an example
Can you suggest books/links that contain examples of complex views?
This link talks a lot about this.

Resources