Proper ASP.NET MVC 5 Approach - asp.net-mvc

Looking for some guidance as I am struggling here.
As someone who spent many years developing ASP.NET applications - that has been out of the game for 3-4 years, I am struggling to pick up the latest approaches. Probably as a result of a decade of experience.
My ASP.NET in the past was built using stored procedure calls, and the GUI was built using hand-coded HTML and JavaScript. I used JavaScript to emulate Ajax type functionality (before it was really a well known thing), and also would at times use XSLT to separate presentation from code.
Now, I am trying to move to MVC 5. It's not intuitive to me, and the few popular tutorials out there seem to be doing things that I don't want to do. For example, they are connecting to a simple table through EF, and allowing a user to view, edit or create items.
I'm looking for some basic things:
How do I get data from a stored procedure into some form of a view (GridView, or ListView, etc) - Using a controller, a View, a stored procedure as the data source (using Entity Framework? When i try DB First, and select to include procedures, I can't find them anywhere)
I'm going to want to allow them to override the value in one column. This would be stored down in the database as a different field.
This stuff was always very simple using basic web forms, but I can't find a tutorial that allows me to do anything other than just edit an existing table using EF - which isn't what I want to do. So tempted to just go back to the old fashioned way ...
This is one tutorial that was making sense to me, until it jumped into the code first approach on the database, where it went off the path from what I was looking to do:
http://www.asp.net/mvc/overview/getting-started/introduction/getting-started
Here was another one:
http://www.asp.net/mvc/overview/getting-started/database-first-development/generating-views
But this one was also different than what I was hoping to do.
I wish I wasn't so short on time with this project.
Thanks for any guidance.

You may better wait for ASP.NET 5/vNext/MVC6 release and don't waste your time on MVC5. If your project relies on SQL and works well do not use Entity Framework at all.

Related

Is there a simple way to add a model in ASP.NET Core MVC via the GUI, besides the package manager console?

At work, I use ASP.NET MVC (not .NET Core) with Entity Framework and SQL Server. However, I wanted to practice a bit with ASP.NET Core MVC and some other SQL Server stuff (like experimenting with SSIS) at home, so I set up a small dev environment for me to work in. I created my database and tables, populated it with information, and created the default template you get with ASP.NET Core MVC. No issues so far!
But then, when I went to add a model into my project, I had no option to add an ADO.NET Entity Data Model like I do at work. After googling around a bit, I saw a mention that you could not create these kinds of models in .NET Core applications: https://learn.microsoft.com/en-us/answers/questions/357012/can39t-find-adonet-entity-data-model-missing-visua.html. I did some more googling, and it seems like just about every single thing I'm finding online is that you have to use package manager console, and type it all out.
Is this really the only way? Surely there has to be something better... It was very nice in ASP.NET MVC when I could add the model, and then it would take me through a wizard to get everything set up. I could create a new connection string, test the connection to the database, select which tables/views I wanted to add to the model, and I was all set! It was just as nice being able to go into my model and easily update the model with new tables, columns, or anything else I needed.
I get that code-first solutions are more mainstream these days, but I want to stick with the database first approach. Is there a simple, user-friendly (non package-manager console) approach for me to add models like I used to, but still get the benefits of .NET Core? Any good tutorials out there to get me on the right track (that aren't code first)? I appreciate anyone who can point me in the right direction!

Avoiding tables (HTML) to show business information

I want to learn new techniques to show business information to my user.
I'm working in a management system that is a web aplication and it's been writen using MVC Razor .NET, Entity Framework and Angular JS.
In a particular page my client wants to see a bunch of information and he's used to use excel, so he asked me to make a table to keep the excel similarity. BUT here is the point I want to improve him experience.
I dont want to use tables, because it is a lot of information (at least 15 columns), I know that I can have some column selector so the user can choice what columns he wants to see and that kind of stuff but the problem is that is very import to him see all informations right away.
I wonder what kind of UX techniques, methods or frameworks I can use to give him a better experience.
Thank you.
That's what tables are meant for. If you are looking to make it clean and easy to manage I would use bootstrap and maybe a jquery plugin like the following:
Bootstrap Example
http://getbootstrap.com/css/#tables
http://www.datatables.net/

PhoneGap development roadblock: framework questions and opinions for a small CRM

I'm trying to achieve a relatively easy goal: create a simple cross-platform CRM app to manage contacts/customers and their relations with companies. At the current state I'm fairly confused on how to approach this (after some early motivational success).
After half a year of Objective-C and iOS development under my belt I wanted to get more serious and start on a real app project, which would be the mentioned CRM app. Then I heard about PhoneGap, tried it out and was very impressed. From there on it was clear to me that my app should be cross-platform.
To have a better understanding of what I'm trying to achieve, here are some details about the "requirements":
Simple data model, 5 or 6 entities total. One-to-Many and Many-to-Many relationships.
Have a tab-bar widget to quickly toggle between companies, clients, etc.
search-as-you-type on listviews
master-detail view behavior for listviews
back buttons on the header, "add/edit" buttons as well. Classical app layout as you would expect.
My first steps lead me to JQuery Mobile for the UI which, at first glance, looked like the perfect candidate to quickly build a UI that fits the requirements and takes off a lot of coding from my hands. The mockup I created worked great on all devices, but then I hit a roadblock: the master=detail view navigation/routing. I had no clue how it's supposed to work and the JQuery Mobile docs don't supply an answer or best-practice for that. I figured out that I might be able to just pass an "id" in a querystring and read it on the details view. That worked to some extent, but only when the page is in an external file (detailsview.html?id=3) and not just an internal one (#detailsview?id=3). And even then I experienced some odd behavior when reading the value from the querystring on the pageshow event. Anyway, all this tinkering with logic and design led me to the clue that there must be a better and more organized approach, something like MVC. And apparently there is, namely backbone.js and Angular.js (and ember.js etc.) that come with decent deep-linking. Some googling told me that Angular.js might be a better fit for me since it comes with 2-way data-binding and makes me write less code, which is always appreciated.
But then there's the problem of a functional overlap between JQuery Mobile and Angular.js since JQuery Mobile has it's own routing capabilities. I could disable that part I guess, but I would probably lose the page transitions in the process (no more "pages" in the index.html)? I found topcoat as an alternative for the UI but it currently lacks a much needed/wanted tab-bar widget as it seems. Just as Twitter Bootstrap which seems to lack it as well.
And I haven't even touched persistent storage yet! The PhoneGap API provides storage capabilities but after some years with nice ORM implementations like Hibernate, Entity Framework and Core Data I want something more "natural" than pure SQL. On the other hand, pure SQL might be doable since the scope of the project is somewhat limited. So I came across JayData but have't tried it yet. Since Angular.js seems to prefer data input in JSON format, maybe Lawnchair.js might be a good idea? I looked into it but I couldn't quickly find out how to reference relations and/or objects in a traditional way. My learning curve aside, is lawnchair.js a good way at all to store relational data? Or CouchDB from a server perspective? Most of the examples I found only stored non-related data or contained arrays not referencing other objects. I guess all it needs is storing the object identifiers in those arrays, but how to do auto-create, auto-increment them and make sure that they're unique?
I would greatly appreciate your thoughts, comments and a little guidance on this :)!
Thanks a lot!
During the last weeks I was playing around with a bunch of storage and UI solutions, the ones that I settled with are lawnchair.js, JQuery Mobile and some other things like Handlebars.js for templating. They are fairly simple to use and exactly what I needed.
To store my JSONs I created Lawnchairs like this:
var clients = new Lawnchair({
name: 'clients'
}, function (store) {
// I don't really need the callback here
});
Lawnchair's JSON based storage makes it simple and intuitive to store your data directly in your javascript code with a single line:
clients.save({firstName: "Jason", lastName: "Bourne", ...});
This will also fully automagically create a unique key for you to access the object later. Big bonus that wasn't mentioned anywhere! You could create and define your own key, but for my purpose the auto-generated one fits perfect.
To create realtionships with your other Lawnchairs, like "companies", you could add the key to the querystring, read it on the detailspage, and add the key to the company's property you want, like:
myJSONclient = clients.get(SuperLongAutoGeneratedKeyReadFromAueryString);
// Probably do some stuff with the object
// Add the key to the current company object
currentCompany.bestCustomer = myJSONclient.key;
// save it
companies.save(currentCompany);
That's all there is to it :)!

Is MVC Framework ill-equipped for rich page design?

Just to prefix this question, I've decided to take a look at moving our works old legacy systems (40+ programs from vb6, vba, vb.net to c#.net) into two separate systems using the same DAL (barcoding terminals and one web based system) as I spend most my day fixing crummy or non existant business logic in 15 year old vba programs. I've recently built an entity framework model complete with fluent validation and couldn't be happier with it after using it for a bit.
The small team is familiar with webforms (but not very) but the last few days I've explored MVC Razor. I was loving MVC Framework until I tried to start trying to add more functions onto the same page and then it seemed arbitrarily hard to replicate our a recent system I put in a webform. Before, I would eager load a customer and all it's child entities and then bind that to single page for the customer so they could access everything (which is what they wanted), it works okay and isn't slow. From this single page I could edit all their account details/contacts/emails/phones/jobs.
All the examples I've done and seen in MVC handle a single update, a single edit etc but surely you can't separate out every single action into a new view/page? I can pass a rich model through to the view in MVC, but then its a pain trying to update all the different child entities.
This is probably the exact design that MVC wasn't designed for maybe, which is okay, I'm willing to adapt it if MVC will be a better platform going forward, but how are you meant to handle adding this complexity in? Some methods I've seen:
Lots of partial views? passing child info to them (or the id and lazy loading it)?
I've seen methods that wrap multiple <forms> around everything and handle actions that way.
Separate pretty much every task out
If the solution is more lightweight and easier to maintain I'll go research whatever I need to I just wanted at an earlier stage to see if I'm wasting my time. Any pointers to the correct questions I should be asking would be greatly appreciated.
ASP.NET MVC is neither more or less better equipped to deal with complex pages than any other technology out there.
Certainly, MVC requires more low-level work than a Web Forms app, with no direct binding support, but in most cases this is a good thing and provides much more flexibility in how your page is rendered.
One of the whole ideas of MVC is to give you more control over things, but that control leads to requiring more knowledge and more effort on your part in most non-trivial cases. MVC provides a number of tooling functions to speed up trivial work (like creating standard table based CRUD) but when you have complex models, you will have to do much of the work yourself.
This is not that MVC is "ill suited" for it, but just that control and flexibility has a trade off with more responsibility on your part.
In your case, you simply create a view model with all the fields you want. Then, you create your form to edit those fields. In your controller, you will need to unflatten that view model and create or update the necessary records in the database. It's not difficult, but it's more work than WebForms databinding.
You could look into more advanced tools (commercial) for MVC, such as Telerik's tools, which have developed more of a databinding like interface, but MVC is not a drag-n-drop technology, and requires you to hook things up and write the various logic for what is done.
If you need drag-n-drop, databound functionality, then no.. MVC is not the correct technology. But then WebForms requires you to accept many compromises as well, and ties your hands in many ways.
You could use partial views, however I seldom use them. I prefer to instead use Editor/DisplayTemplates as these take care of naming your form fields correctly, even for collections and complex objects. PartialViews tend to have lots of gotchas if you aren't careful. I pretty much only use them as fancy includes, or when using Ajax.
I'm not sure what you meay by "wrap multiple <forms> around everything`. You cannot nest forms in HTML, it's not legal. If you mean place a form around each row of a table, that isn't valid html either in most cases (it's not legal to put a form in a between the table and the tr).
It would help if you had a specific problem that you could ask about, vague objections don't help us solve your issue.
You can accomplish anything in MVC that you can in WebForms. The difference is MVC will usually require you to write more code as it doesn't really offer you any "controls" to drop on your page.
In WebForms, it's easy to create a master/detail view with a GridView, FormView and then wrap everything in an UpdatePanel for automagical AJAX support.
In MVC, while you do have helpers like the WebGrid and AjaxHelpers extension methods, creating views and/or pages requires more understanding of how things work to get the desired functionality. When I start a new MVC project, here's what I include:
Backbone.js - client-side "ORM" that performs CRUD operations
against RESTful* APIs
Knockout.js - client-side view models and
real-time data-binding for your views
Knockback.js - wraps
Backbone models in Knockout view models
Using these three frameworks, you can quickly create powerful single-page apps using MVC and WebAPI.

how to access the radioButton in grid View?

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.

Resources