I've made a music store using the tutorials on ASP.net and they do not show you how to make a billing page. What I would like to know is would I have to make a new controller and view for it or will I just need a view and to add a piece of code to an existing controller? Also, how can I make the page so that it authorizes the details given, for example, will know when the card details are not correct like the wrong security code or wrong card number in general?
Much appreciated
So you need to continue to tutorials on asp.net mvc site you should try the tutorial on models page code first with entity framework there are so many samples about validation.
For the credicard validation there is an algorythym of this named Luhn Formula, so really you don't have to know how to validate, there is a asp.net code that has been written and works on the link also you can use javascript validators on view to give better service.
http://www.codeproject.com/KB/aspnet/wdxcreditcardvalidation.aspx
you just need to write a code on controller (it just to show you how it's done, you may need to write additional codes)
if(luhnisvalid(Order.billingdetails.CreditCard))
{
// then adding to database
}
or return to view
return(View(Order));
and finally continue to this tutorial it will give you so much information, after the tutorial i'm sure that you can make the billing part.
http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Related
I need to create a multi-step wizard using ASP.NET MVC.
After thinking about this a while, I feel like the most efficient solution is to put the content for all my wizard steps in a single view, and just step through them by hiding and showing elements using jQuery.
But one area I'm not totally at ease with is MVC validation. How could I validate each step this way? Seems like I won't know for sure if the data is valid until the final step is completed and the entire page is posted back to the server.
Any suggestions?
You can validate individual controls using Validator.element(element) - see documentation here. An example of the approach I think you are taking is in this answer
This more of an out of interest question than an urgently need an answer one, but I have been trying to find a good example of how to deal with a full postback from a partial view in asp.net MVC. The obvious example is the case where you have a small login form on every page. You can easily accomplish this through an asynchronous post back using jquery, but I am wondering if there is a way to do it without the use of javascript. I know it may be pedantic, but I don't like the idea of assuming the client has javascript enabled, particularly in this day and age where responsive design/ progressive enhacements are the big buzzwords around, so having you log in tied to javascript means that anyone on a simple mobile device won't be able to use it since their device probably won't support it.
Anyone have any ideas / examples of how to accomplish this? It's such a simple thing to implement in web forms I can't believe it's as tricky as I've heard it made out to be in MVC.
You just need a form within the view, that's all. The form will POST to its controller action method and generate a full page refresh (if that's what you mean by a full postback - I guess it is) irrespective of whether its a partial or not.
You can have multiple forms on a MVC view, and each one of them will give you a full page refresh, whereas with WebForms the pattern was one main form per page.
I'm trying to learn the asp.net mvc. I have worked with most of the samples that MS have published.
Most of the samples is just about CRUD.
I'm pretty good at working with webforms, but now I kind of miss the old easy world.
But, my question is: I have a detail page that is connected to an order, I have the order details comming along all well. I got my order detail lines kind of work. But now I would like to do different things with this order, like add more order lines, change the order status with a button, email the order and so on. In webforms I just added eventhandlers on the click event, but here... Do I need multiple forms? How do I make serverside code for example when someone wants to change the orderstatus with a click of a button?
Hi i can recomend you Pro ASP.NET MVC 2 Framework book by Steven Sanderson
I'd recommend you go through the entire NerdDinner tutorial.
But to answer your question:
There really are no forms in asp.net MVC. There are views, which show your order, and there are controllers/actions which allow you to run code to generate views, update your database, etc. You ask if you need another form - the answer is No. You will, however, need at least a new action on a controller, and possibly a new view to confirm that the order was changed. An overview to a very simplified solution would be:
You want to allow an order to be marked as closed by clicking a button. Assume you have a controller called Order, and a view (in the order views folder) called Details. You'll have to add an action which takes an integer as a parameter to your order controller called "Close". In that action, you'll read the integer parameter (the order ID) and execute code to update that particular order to closed. You'll probably want to return the same view with the udpated status from this action. You'll have to add a link (probably using HTML.ActionLink function) to your view to call this new action.
In MVC everything is Post and Get actions. You can post to difference controllers. It seems you need to spent a bit more time reading about it. If you do not fancy reading - try some nice video tutorials for beginners. http://www.asp.net/mvc
using data source we can show the data in web page. but i want that there is radio button with all rows and after accessing the radio button the given functionality works?
how to do it please explain?
you need to be more clear with your question - if you already have some code then post it and then ask the how your code needs to do something specific
since the comment was amended
in ItemDataBound event
do something like (e.FindControl("controlname") as RadioButton).SelectedValue
im not quite sure if its c# or vb that you are writing in so cant be more specific at this time
Based on your comment in the other answer I understand that you're actually using WebForms server controls with Asp.net MVC application.
Avoid mixing an matching Asp.net MVC with WebForms
Unless you're skilled in both platforms I suggest you avoid this. It will only bring you headaches in the long run. Displaying and consuming checkboxes/radiobuttons (or any List<T>) should be done differently in MVC. Check this questions (and answer) out that will help you out and show you how this can be done in pure MVC way.
It also explains what things to take care when you dynamically add these items on the client side using Javascript.
I'm still just getting into MVC, and for my first real project I plan on creating a blog. This will be extremely basic (at least at first). Everything I need is going to be on the same page. Here are the initial features I am shooting for:
User should be able to log in, but not register (I will be the only one able to post, and I added myself directly to the DB.
Blog posts should be listed in descending order with a Title, a post date, and the body. No comments required for now.
The bottom of the page will always have an area to make a new post, assuming you're logged in.
Since I'm still new to the MVC structure, I'd like some advice on how it should be organized.
For my models, I figured I should have a post repository and a BlogPost class for the post data which can be used for both the posting and retrieving. I would also need a class for the user.
When it comes to controllers I'm a bit less confident. Should I have a different controller for every type of action? For example, posting should have a controller, retrieving should have a controller, logging in should have a controller, etc?
As for the views, since I really only need a single page, should I only have a single view and have that view output the appropriate content from my controllers?
Just let me know if I'm on the right track, I suppose. If my thought process is way off, please tell me. I've just started working my way through Steven Sanderson's MVC 2 book, but I feel like I need to go out on my own and play between my reading sessions.
Thanks.
Controllers should be grouped by functionality. You could also have a controller per resource (REST). You could have an AuthenticationController which handles authentication and PostsController which will handle the posts retrieval and adding a new post. As far as the views are concerned assuming you will have a single page that will list posts and add new posts you could have a single view but maybe with multiple partial views/editor/display templates.