Updating a form from a partial view from JQuery - c#

I'm a freshman in ASP MVC3 and very very very freshman in JQuery
I'm working on an ordering process for some items, how it's working currently is when the user clicks on the 'Create Order' link,they are taken to a list of the items to be ordered (formatted using a table) and after clicking on an item, a form loads containing details of the selected item, at this point the user can add additional information on the form before creating the order.
I would like to simplify this process by having the user work from one view. I would like this view to have the above mentioned form and a partial of the item list mentioned above, so that when the user selects an item on the partial, the form is loaded with the item details without opening a new page.
QUESTION is, how do I load up the form with the selected item in the partial view? I'm stuck at the JQuery part, no idea how this script will look like.

I guess that you could take a look at AJAX. Maybe even read some tutorials or watch a couple of videos and learn how it could integrate with ASP.NET MVC could be useful for your current and future projects. Of course you shouldn't hesitate to come back to Stack Overflow once you have a specific question to ask. You could show your efforts and code, explain the difficulties you have encountered and we would have a common base for discussion.

Related

How to use single save and delete button for multiple page in asp .net or mvc

In my last interview, the interviewer asked me this question. Question is:-
There are four pages having a different form, how to use common save, delete or update button for all the pages and also methods for all are common like save button will have a common function for all four pages. I have tried to answer as per my knowledge, but he is not satisfied with my answer. He said that, can we implement an interface for this purpose. But I am not able to answer him.
If you have any solution please suggest, thanks in advance.
My suggestion was based on MVC. I have told him that i have a common model for all four page with all required properties and a property have page name. In post method based on that property i use if else condition for different pages functionality.
One solution is to have a master page which has Save, Update and Delete buttons. Then these buttons along with all of their events are shared between all Forms which are having that master page.

ASP.NET WebForms, DropDowns, Submit Button

I have struggled to find a solution to this problem through lots of Google searching and documentation reading, and even looking at others’ source code, but I am putting it here in the hopes that someone knows how to help me or has specific experience in dealing with such a thing.
I am currently working on an ASP.NET WebForms project with some of my colleagues, and we have decided to go with an option of which I was not a fan. We have created a page where the user will be required to fill out the university classes they have taken, with related data, in a massive sheet of dropdown menus.
These dropdown menus are pulling their associated data for the user to choose from the database (SQL Server, a.k.a. “Microsoft SQL”), as a way to partially limit user error. The user will make their selections on none, one, some, or multiple dropdowns from multiple “rows” on this page.
My question is how I can write an SQL Server query, and thus, stored procedure, that will allow for a “submit” or “save changes” button to be added to this page. When a user clicks this button, presumably, all of the changes that they have made on any of these “rows” – one row per class – will be added to the database for their respective user account.
My suggestion was having that page be an ASP.NET Grid View that would update with the classes that the user had taken as they entered them. There would be a button at the top of the page where the user could click “Add Class”, and they would be taken to a model popup or some other page, and they would enter the details of that class, mostly through predefined information that is pulled from the database. In the case of an administrator user, they would essentially be able to put whatever information in for the class, because they have the ability to override the strictly regulated format for regular (student) users.

what is the best way to design a wizard form in ASP.NET MVC

i want to design a form in asp.net in Wizard style. do something in click next.
the form have 3 step
fill your information
add element [here if you type something wrong then you can edit or delete them before going to next step]
finish
what is the best practise to design this in ASP.NET MVC with a power of ajax.
are anyone show me the best way i can use to do this in MVC
Here's how you could proceed: the elements of each step of the wizard could go into a separate div. The Next and Previous buttons will show/hide the corresponding div. On the last step there will be a submit button which would send the entire form to the server.
You might also take a look at the jquery form wizard plugin.
One of the ways that I have implemented a wizard is to have a separate database table that contains all of the information you are required to store and to save/retrieve data to that table in each step of your wizard - obviously depending on the size and purpose of the wizard this may not be sensible with the number of database calls but I was implementing only a 5 page wizard with maximum 5-10 fields on each page. So when you land on a page you query the database and retrieve the information from the database or if it doesn't exist load a blank page where the user can then enter the information and it is saved when they click either Next or Previous.
For navigating between pages I simply built a helper class that accepted the page name and button type (Next/Previous) and had a simple switch statement which would return the page to navigate to and then used that in a RedirectToAction statement. Again this may not suit a larger application but you could also look at using Windows Workflow (touched on in this article http://www.devx.com/dotnet/Article/29992) as I know that it can be used to create wizard style applications.
It is not particularly an MVC solution but I advise a client-side implementation using JQuery LightBox.
You don't need any client side stuff to achieve this, it's also bad practise to use javascript for anything other than user convenience.
You have 2 problems with a wisard:
1: maintaining state. ie saving data between requests.
2: figuring out which action (usually next or previous) to take.
Maintaining state.
You can use the session object but ideally (and so you can unit test them) all actions should be pure functions. I use hidden inputs to save data between requests.
User actions.
For a next / previous view. Add 2 submit buttons to your form and give them names. When you
POST the form, the button with the none null value was the button pressed. Then redirect to the appropriate action.

New MVC2 Application Suggestion

I'm starting a project in ASP.NET MVC2 where I have a need to let the user select item(s) from a table with about 40000 records. This is NOT a shopping cart application.
I'd like to accomplish this using JQuery popup. Here is the order I have in mind...
Please think of this as building a new car
Customer starts to build a new car
Enters some basic info such as name, # of cylinders etc
Clicks an icon to show a JQuery modal popup to search parts required
Selects an item/part after the search returns
Selected item shows up on the underlying [parent] page.
Repeat steps 3, 4, 5 to select additional items/parts.
Then Save to database in a Master/Detail type tables
This is similar to a shopping cart except there is no checkout and the user enters the order info before making the selections and I noticed that JQuery interfaces seem to appear richer.
If this is doable, I'm looking for suggestions and/or examples or a path to follow, being new to both MVC and JQuery.
Example of what I want to achieve can be seen at www.pageonce.com, only in a much smaller scale.
TIA
ASP.NET MVC2, MS SQL Server, JQuery
Start with understanding how you will achieve Ajax with Asp.net MVC. Another suggestion is that consider moving to Asp.Net MVC 3. You will get Razor view engine and lots of Web Helpers which can enhance your UI further.

Manipulating page scrolling when returning a View in an ASP.NET MVC site

I'm building an ASP.NET MVC site where I want one of the Views I return to be automatically scroll to a certain point.
The part of the site where I want this to occur works sort of like a forum - there are "threads" that contain "posts". A user can either browse to the whole paginated thread or can browse to a specific post, using its ID. When a user browses to a specific post, I want to show the regular thread interface, then browse to the page that the post is on and scroll down to the post.
Is it possible to somehow automatically scroll down to a certain point when returning a View from an action in an ASP.NET MVC site? If so, how do I do this?
NOTE: One solution to this problem that I've found is how Stack Overflow and the other Stack Exchange sites do it: each answer to a question can be linked to by adding #ID to the URL. If it's impossible to automatically scroll down when returning a View, I would implement this instead, but I don't understand how to use such an approach when there are multiple pages and the post in question isn't on the current page.
UPDATE:
Based on Chris' answer, I'm currently planning to implement it with the URL looking like this: example.com/forum/[ForumID]/thread/[ThreadID]/post/[PostID]#[PostID]. In my Action, I figure out what page of the Thread the Post is on, and then I return all the Posts from that page to the View.
However, I noticed something special in how Stack Overflow solves this problem. Try going to: https://meta.stackexchange.com/questions/57170 - it ends up sending you to https://meta.stackexchange.com/questions/57155/gravatar-bugs-and-improvements-in-chat/57170#57170.
How is the above implemented? This is exactly what I want to accomplish.
You can use javascript in your View to achieve automatic scrolling, with something like the jQuery ScrollTo plugin (http://plugins.jquery.com/project/ScrollTo). Attach it to your page load event and target your desired post.
However, the simplest way (and most cross-browser compatible) would be like how StackOverflow does it, with the #ID in the URL.

Categories