How do I implement a "registration confirmation" in ASP.NET MVC? - asp.net-mvc-2

I'm an absolute beginner with ASP.NET MVC and I'm trying to build a pretty simple application, but I'm having a hard time getting out of the webforms thinking.
I need to register users so they can download my application. I need to capture their information in three screens. Rather than write the database from each view, I want to aggregate all of the data they enter and let them confirm it before they submit their information.
I've been playing with various models and such but if I make one big model, the scaffolding wants to put all the fields on one view.
Can anyone point me in the right direction?

Sounds like you need a Wizard. Here's a few samples:
http://highoncoding.com/Articles/647_Creating_Wizard_Using_ASP_NET_MVC_Part_1.aspx & a youtube video
http://shouldersofgiants.co.uk/Blog/post/2009/09/18/A-RESTful-Wizard-Using-ASPNet-MVC-2e280a6-using-Data-Annotations.aspx

ASP.NET MVC is stateless, which means it doesn't save state between views like Webforms does.
You should save the information from each view into the database, and then set a flag in the user's database record at the end, indicating that the user confirmed their information.
If you need three separate views, you can always copy parts of the code created by the scaffolding to each of the three new views, using only those fields you want the user to see in each view.
If you need validation in each view, use a ViewModel object for each view that pertains only to those fields in the associated view.

Related

Angular 4 - Saving form data of highly complex form

We have highly complex form in Angular 4 and we want to be able to save form data as an object to be able to send to our DB and also to external APis in json.
Form has tabbed form wizard format and each tab had lot of form controls and each tab itself is very complex.
So we plan to create a data service where at each step, we plan to put data in an object, and keep updating as we nagivate till the end. If user clicks save drafts at any time in form wizard, current state of form data object will go in DB.
Form next, previous work same way, retrieve or updating form data object.
When saving form or submitting form, we will have post http call to backend.
Is there any better approach to achieve this? or we are following right direction. Any examples will be great.
No better approach. You put your complete model in the service. Than create sub-models inside that model that correspond to your individual tabs. In each component, get the model from the service, and keep updating the appropriate model for the tab you are on.

Multiple edit forms based on a template form

I'm working upon a small-scale enterprise database application. It works with such business objects as Vendors, Device types, Devices, Suppliers, Invoices, Departments, Employees etc., so I need to let users view and edit data from all these tables.
My first approach was to create a pair of forms for each type of business object:
a table to view and select an object
an editing form for this type of object
But now I find it hard to maintain all these forms, because e.g. if I want to change the look of all view forms, of course I have to edit each one of them.
So I want to replace all my view forms with a single one "template" form and to call it with some kind of parameters. The problem is, I don't know the right approach to perform it. Maybe there could be some example in some book or somewhere else?
I think the best way is by using Visual Form Inheritance .
Actually we use this kind of programming a lot, it keeps maintenance pretty simple. Stick your base functionality in the parent form, and specific behaviour in the child forms.

MVC Design in iOS

I am creating an iPhone app that allows you to specify certain criteria, fetches a list of events from a web service, and lists the events in a table view so that users can add the individual event to their calendar.
How should I approach this with the MVC pattern? Will be using JSON.
Any ideas?
If you are going to be consuming JSON based web-services, you might want to check out AFNetworking. I wrote a network class to work with AFN, check out this SO post for the code.
User calendar and the list of events and how you fetch them is the model. Table view is the view. Classes that glue the two together are the controller. Doesn't matter if you use JSON or whatever else if we are talking about general architecture here.

Storing country specific(static) data in database or in an class in MVC2 application

What is the best way to store static data in MVC application? Data like country and cities.
1- Should the data be stored in database and called everytime a view requests it and populate the dorp down?
2- Create partial view of countires and use it in different forms when needed?
3- Create static classes?
4- Create class and static method which returns the list?
5- Use caching?
Or any other idea would be appreciated.
Also the dropdown list should work with ajax, like selecting country should load the cities, selecting cites should load the region?
Hekim Başi
MVC stands for Model View Controller. Controllers 'control' your data, they do something with it, views are pretty much html, to show your data to users. Models are what you are looking for here, they store data in a way you can acces easily. As soon as you get the data you want, you store it in a model, then acces (and maybe alter) that data with your controller and finally pump it to your view, so the user sees your application.

Image handling in multi-tier ASP.NET MVC 2 app

I'm looking for some help wrapping my head around a good approach/architecture to handle images in my ASP.NET MVC 2 application. The application is a client for a middle-tier web service application that encapsulates our domain logic and rules. The images are stored in a back-end database that is only accessible through the web service.
For the sake of this discussion, we'll use the classic case of a Product which has an associated image. Whenever I display information about the Product, I also show the image. So, for instance, when viewing a list of Products to an admin for editing, I will show the image and the name of the product as a hyperlink. when editing, the user can see the existing image and upload a replacement. I also show the image when users browse lists of Products or look at what items are in their 'shopping cart'.
Needless to say, I have to obtain the image data a lot. (And, yes, caching will be a part of the solution but not part of my question.)
My first task was to create the controller and views used to edit Product data which includes the ability to upload the image. I followed the approach described in Pro ASP.NET MVC 2 Framework where I set the image element's src to a controller action which returns the image data. The controller receives a reference to the ProductManagementServiceAgent in its constructor and delegates to the agent which handles the call to the web service. This works great but, of course, it means two calls back to the service to display the information.
Next I have to display the list of Products, with images, to the admin. In this case it's not a problem because I'm using the same controller with the same action, so I can use the same approach. Unfortunately, now I'm making 'n+1' calls to the service.
My quandry comes when figuring out how best to handle all of the other use cases where I need to display the image. Inside the 'shopping cart', for instance. Should my ShoppingCartController also reference ProductManagementServiceAgent and use the same method to retrieve the product image? This would mean any controller that displays a product image would have to reference the agent, yes?
The first thing that bothers me about this is that I don't like injecting multiple dependencies into a class if I really don't need to and see long parameter lists in constructors as smelly code (tells me the object is trying to do too much). Plus, the ProductManagementServiceAgent is really intended for the admin UI, so maybe a different agent would be better? Or a different approach all together?
I have to think that others have already charted this territory, so I appreciate any wisdom to set me in the right direction.
Have a dedicated controller for images.
It will have one dependency - the ProductManagementServiceAgent.
Cache it both server side and client side to minimise requests.
I actually went with a suggestion not posted to this site so I can't give proper credit. In a nutshell, we expose additional actions on our controller when an image is required. So, for instance, our ProductController has a ProductImage action method that accepts the product id and returns the image. It seems to satisfy our needs.