ASP.net MVC has matured significantly over the past few years and is perhaps one of the best web frameworks out there to develop secure, fast, enterprise web applications. The team at Microsoft is constantly working on the development of the product and updates being pushed to the framework has always been very well tested and dependable. This has made ASP.net MVC a serious contender as framework of choice for web development. Add to that the beauty and power of C#, needless to say developing in ASP.net MVC is certainly a developer’s pleasure. However, before taking a dive into ASP.net MVC for that matter any MVC framework, whether web or not, the developer has to think in a certain mindset. ASP.net MVC like other popular MVC frameworks such as Ruby On Rails or Spring MVC etc. has a convention over configuration approach. The question will arise what is convention over configuration? Well, to put it simply, a convention is a established way of doing something (such as naming a class etc). So how does a convention better over configuration? By following the established conventions we cut down on a lot of boiler-plate work. In today’s world where extreme programming, agile development are the mantras, every developer worth her(his) salt wants to cut down on mundane tasks as much as possible. With this in mind we will start our ASP.net MVC step by step tutorial and before that let me tell you the full source code for the project is available at GitHub as a public repository and can be pulled from the link below
Download complete source here
- What are we building
- Approach
- Tools
- Steps
What are we building
We are building a simple E-commerce application, which has all the features of (well most) modern day e-commerce websites, like a catalog, product categories, a shopping cart, checkout mechanism, an user authentication module and a content administration module. For the Java developers Netbeans documentation had a e-commerce tutorial called AffableBean and it can be found here. The tutorial uses older Java EE technologies to put together the E-commerce website. The same was replicated to SpringMVC by a developer and the details can be found here. So we are replicating the same application with some more features than those apps have to show the ASP.net MVC development perspective and also to allow developers to see the differences between the technology stacks
Our approach
ASP.net MVC now recommends a Code-First Approach to application development. And it is highly recommended to utilize the ORM (Object Relational Mapper) called Entity Framework to be used as it is developed and maintained by core ASP.net team although there are other ORM choices like NHibernate etc. So what is code-first approach? In code first approach we define our domain objects(entities) as POCO classes. A POCO(Plain Old Clr Objects) is nothing but a simple c# class. For example have a look at the below Product class
public class Product
{
public int Id { get; set; }
[Required(ErrorMessage = "Product name is required")]
[MaxLength(45, ErrorMessage = "The maximum length must be upto 45 characters only")]
public string Name { get; set; }
[RegularExpression(@"^\d+.\d{0,2}$", ErrorMessage = "Has to be decimal with two decimal points")]
[Range(0,5,ErrorMessage = "The maximum possible value should be upto 5 digits")]
public Decimal Price { get;set; }
public string Description { get; set; }
[Display(Name = "Updated At")]
[Column(TypeName = "datetime2")]
public DateTime LastUpdated { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<OrderedProduct> OrderedProducts { get; set; }
}
As you can see it is a simple c# class with few Annotations. Those annotations make Entity Framework to generate validation rules or create a display name attribute while generating scaffolding code for us. With this class and a Data context that inherits from DbContext is more than enough to create the database table for us by Entity framework. Lets look at the datacontext class below
public class MvcAffableBeanContext:DbContext
{
public MvcAffableBeanContext() : base("MvcAffableBean")
{
}
public DbSet<Product> Products { get; set; }
}
Again here we are basically doing nothing the whole work is being done by the DbContext class defined under System.Data.Entity namespace which is part of Entity Framework. Many people ask how to target a database name of their choice while using entity framework, as it turns out it is very simple and I will explain the trick here. Have a look at the Constructor function
MvcAffableBeanContext() : base("MvcAffableBean"){}
We are basically using the base keyword to use the constructor with the connection name overload which is defined in the DbContext class. Apart from this we also need the Web.config to have an entry as follows:
<connectionStrings>
<add name="MvcAffableBean" providerName="System.Data.SqlClient" connectionString="Data Source=.\sqlexpress;Initial Catalog=MvcAffableBean;Integrated Security=True;" />
</connectionStrings>
This shows how smart Entity Framework is, it will take the Id property of the class and create an Auto-increment id table in the database which will be primary key, if we named it differently instead of Id or ProductId then we have to annotate it with [Key] annotation to make Entity Framework know, we want that field to be the primary key. Another interesting thing to learn is Navigation properties and virtual keyword. Navigation properties are essentially relationships. For example looking at the following line of code in the product class
public virtual Category Category { get; set; }
and
public int CategoryId { get; set; }
tells us that Category Id is a foreign key in product table and looking at the Category.cs file we will find this line
public virtual ICollection<Product> Products { get; set; }
Reading both in conjunction we can easily know that Every product belongs to one Category and a category can have many products hence the
Icollection<Product>
So this demonstrates how easy it is to create relationships and we can access relational data from the other table in our code using navigation properties and .(notation) just like accessing data of objects. Once you download the source code from GitHub have a look at all the classes inside Models folder which by convention stores all our domain objects. The virtual keyword provides lazy loading i.e. do not load all items into memory until it is needed. Have a look at the conventional folder structure of asp.net MVC
Tools used
- Visual Studio 2013+
- Entity Framework 6.1.3
- Bootstrap
- SQL Server 2008+
- JQuery
- Newtonsoft JSON
Look at the end result of the product we are developing



The above were a few selected screens, I encourage you to download the project from GitHub and run it on your system to get complete feel of the project and also to follow along
Steps
- Create an empty ASP.net MVC project choose no authentication we will manually build authentication by copying and pasting from scaffolding code from another individual account project and modify it
- In the Models folder add all the domain classes as found in the GitHub Models directory and build the project once
- Add Controllers one by one scaffolding from the Model and with Entity Framework
- Add Views via right clicking on the controller action from the scaffold
- Create the shopping cart view models as defined in the ViewModels folder from the GitHub project
- We create them as view models as we do not want to persist the data of such complex business tier where complex business logic calculations are happening
- Populate the required partial views for the Cart and Logon section on the navbar
- Create the checkout controller
- Copy the Accounts controller from the GitHub project
- Add the footer JavaScript on the _Layout file
- Import the images and keep the folder structure same
- Run the project
Programming like swimming can only be learned if you dive into it. I hope you will download the project and fiddle with it or create the code of your own and may be enhance the project too. Do hit me up with comments if you want to improve something or if you did not like something. Happy coding!
***Update***
Those who are facing foreign key constraint errors, please follow the below steps, should be fine:
Delete the migrations folder completely and add new migrations, that will solve all the issues:
setps:
Delete the state: Delete the migrations folder in your project; And
Delete the __MigrationHistory table in your database (may be under system tables); Then
Run the following command in the Package Manager Console:
Enable-Migrations -EnableAutomaticMigrations -Force
Use with or without -EnableAutomaticMigrations
And finally, you can run:
Add-Migration Initial







Awesome site…:)
This tutorial helped me getting started in a quick way. Thanks for this
wow, the source code is complete and well commented I liked it. In fact based on this I created my school project. Thank you.
How to download this project with complete source
Thanks for the great tutorial. Hope to see more soon
How can I set-up database to run this solution
Hi if you have SQL Server running you just need to change the settings in web.config to point to your database, rest Entity framework will take care
Thank you very much.
Theewaris Khayim
How can I set-up database for this solution
How can I update the database to SQLServer Express LocalDB
It’s easy , just put the appropriate connection string in web.config, have a look here http://www.asp.net/mvc/overview/getting-started/introduction/creating-a-connection-string
I point the database in web.config
EF didn’t create the tables and initialize data? Or I have to copy data from somewhere else?
No You do not have to copy data from from anywhere, It is important to have the DataContext file though without which EF will not create the db, for example this file
https://github.com/shakeelosmani/MvcAffableBean/blob/master/MvcAffableBean/DAL/MvcAffableBeanContext.cs
add name=”MvcAffableBean” providerName=”System.Data.SqlClient” connectionString=”Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MvcAffableBean.mdf;Integrated Security=True;”
Hi,
You are pointing to an instance of localdb, and if you see the data folder within the solution there will have an MvcAffableBean.mdf file, You have to look that up there
I downloaded project from https://github.com/shakeelosmani/MvcAffableBean. I looked through project and I didn’t see any data seeding but table creating. Am I overlooking something? Anyway when I built and ran project, error occurred as Foreign key ‘FK_dbo.OrderedProducts_dbo.Products_ProductId’ references invalid table ‘dbo.Products’.
Yes you are right, There is no initial seeding of data, however; you can use the admin side to create few products and then they will be visible in the front end. You can do one thing you can code it and go one by one on the domain classes making sure a class that references the other class for example the ordered product will depend on a product class being already created and also making sure you have added few products so that actual table will be created by EF. In fact i wanted all the users of this tutorial to build this on their own so purposely I didn’t create initial seed data, that’s why you are seeing that error message!
I understand your point but to use the site for the first time it would have been good to have tables with information.
I’m having trouble creating users, the membership tables are not created. I Run aspnet_regsql.exe to create them , but I get error connection to the database , however I list Products without problem. So conection to sql seems work ok. 😦
The identity table with users is setup to use a local db so please make sure you have local db installed
Hi I just downloaded the project and I am trying to get it to run on vs2015 and I am getting build errors. Microsoft.CodeAnalysis,BuildTask.cc” task could not be loaded from the assembly. do you know how to fix this.
First try cleaning the project and build if that does not work too then please go ahead do the following:
NuGet packages were committed to the repository and breaking everything. Deleting the project\project\packages directory should splve build problems since NuGet fetches the packages automatically on build.
Please provide a link to download the MvcAffableBean.mdf file. Its not on the solution in Git.
Entity framework will create it automatically if you use the local data option, so there is no such file with me
Sorry for the trouble, but could you maybe guide me to the setting? I’m new to ET and MVC.
You need to do the following:
1) Make sure Entity framework is addede by NuGet
2) Create a connection string as follows:
<connectionStrings> <add name="MvcAffableBean" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MvcAffableBean.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />3) In you DbContext file make sure following exists:
public class MvcAffableBeanContext:DbContext
{
public MvcAffableBeanContext() : base(“MvcAffableBean”)
{
}
public DbSet Products { get; set; }
}
A side note: Also if your Computer has localdata v12 instead of 11 you need to change that to 12
or if any other version is out there
Nice Project!. But am having this error: Foreign key ‘FK_dbo.OrderedProducts_dbo.Products_ProductId’ references invalid table ‘dbo.Products’.Could not create constraint. See previous errors. How do i solve this?
Just change the sequence, don’t execute the project as downloaded,first create the product class then the ordered product class, what’s happening ordered product needs product class but in the downloaded project the file sequence is alphabetical so that one gets executed first hence the error. If you are comfortable with migrations you can use that else just play around the sequence and you should be fine
ordered sequentially but still getting the same error
Hi,
I am trying to learn entity framework, also i download your code from github and execute then i got the error “Microsoft.CodeAnalysis,BuildTask.cc” related and after solving this issue got new issue “Foreign key ‘FK_dbo.OrderedProducts_dbo.Products_ProductId’ references invalid table ‘dbo.Products’.
Could not create constraint or index. See previous errors.”
So, not understand how to resolve them, actually, I am using Visual Studio 2015 Community and SQL Server 2014 Express edition.
So, Could you help me to learn entity framework and current issues.
Hi Ajai,
The error you are getting is because of the sequence of the tables being created. The letter “o” is before “p” hence in Visual Studio file structure the “Ordered Product” table is being created before product table being created. So i would suggest comment out the ordered product class and let the product table get created first and then try to create the ordered product class which has a foreign key reference to the product table
Have fun!
Thanks,
I have run the application based on provided the steps from you. Also, I have one more question regarding entity framework, I have change the connection string accordingly, but its not shown, its appear on data server, but not in sql express. As i saw and read with many article, its store on some local db, and also in web.config find some thing like “mssqldb” under entity framework tag. If i have comment those lines then its through the error. So, my question is how can we connect through SQL Express istead of localdb.
Connecting to SqlServer Express is simple, there are two steps to it as follows, make sure:
<connectionStrings> <add name="MvcAffableBean" providerName="System.Data.SqlClient" connectionString="Data Source=.\sqlexpress;Initial Catalog=MvcAffableBean;Integrated Security=True;" /> </connectionStrings>The above entry is in your web.config (the main web.config at root of the project)
And then make sure you have
public MvcAffableBeanContext() : base("MvcAffableBean") { }The following line in the constructor method with base as this will make sure the database entity framework references is MvcAffableBean, you can change that string at both the places for some other name of your choice
Hi
I get this error message when i build solution
Severity Code Description Project File Line Suppression State
Error The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly C:\Users\Jagjit\Downloads\MvcAffableBean-master\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///C:\Users\Jagjit\Downloads\MvcAffableBean-master\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. MvcAffableBean
Thanks
Hi
I get the below error message when i build solution
Severity Code Description Project File Line Suppression State
Error The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly C:\Users\Jagjit\Downloads\MvcAffableBean-master\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///C:\Users\Jagjit\Downloads\MvcAffableBean-master\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. MvcAffableBean
Thanks
What version of Visual Studio you are using, comment those requirements you don’t need them they come in Visual Studio ultimate edition
VS 2015 enterprise
where is database file …..
where is data base
Entity framework will create it for you
i can’t access your files when ever i click on download link “unable to connect” message on browser showned.
I don’t know what do you mean. It’s a public GitHub repository. May be you have some kind of virus in your system or I didn’t get your question properly
hi, Can i make a database myself?
Database won’t load..
As soon as you run first time after adding Entity Framework package from package manager. The database will be automatically created
Thanks
Hi
Am new asp.net mvc , I need projects, could u provide real time projects plz
Hi
Do we need the Migration folder, if I create a new application, I am getting confused with the migration folder.
Thank you
No if you are building a new application form scratch you don’t need the migrations folder. In fact when you will use the entity framework to create your first migrations, you will have the folder generated
Thanks for the reply
, When I try to Add views by scaffolding for LogOn model and ChangePasswordModel it shows the error,
” Logon Model has no key defined, Define the key for this entitytype.”
Hi Sridhar,
You do not have to scaffold for LogOn Model because the LogOn model is used from system.identity default service for membership that .net has built in all you need is the accounts controller and an entry in web.config like this
<authentication mode="Forms"> <forms loginUrl="~/Accounts/LogOn" timeout="2880" /> </authentication>And you are good to go, the system will use a local db instance to generate store and retrieve the user names and passwords and related information
Thank you
I downloaded project source from GitHub & changed db connection string after that ran application and got exception like “Foreign key ‘FK_dbo.OrderedProducts_dbo.Products_ProductId’ references invalid table ‘dbo.Products’.
Could not create constraint or index. See previous errors.”. You already told, table sequence should be change. Could you please tell me which method should I comment out? better if you point out extact class name/ method name.
Thanks
Delete the migrations folder completely and add new migrations, that will solve all the issues:
setps:
You need to :
Delete the state: Delete the migrations folder in your project; And
Delete the __MigrationHistory table in your database (may be under system tables); Then
Run the following command in the Package Manager Console:
Enable-Migrations -EnableAutomaticMigrations -Force
Use with or without -EnableAutomaticMigrations
And finally, you can run:
Add-Migration Initial
Thanks. It’s work for me
Hi what model classes does the checkout controller and the storefront controllers use?
store front uses categories controller and the checkout controller uses view models from inside viewmodels folder
Thanks for the reply.
Why do you need Newtonsoft JSON tool?
I might have initially planned to create a Store admin interface with WEB API , that requires JSON manipulation, and must have pulled it because of that. However, due to time constraints I did not implement the store admin.
I can’t run this project on my vs2013 ,, the message appear that it can’t be loaded cause version not matched.
Use VS 2015 You can in parallel install both
Hi I get this error when I try to run this in visual studio 2015
Server Error in ‘/’ Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 20:
Line 21:
Line 22:
Line 23:
Line 24:
I am not sure why this happens.
I am not sure without looking at further details, but take a look at the following link:
http://stackoverflow.com/questions/9300927/error-to-use-a-section-registered-as-allowdefinition-machinetoapplication-beyo
So where’s this tutorial you promised?
You can download the source code and follow the general steps I have enumerated in the article
Server Error in ‘/’ Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 23:
Line 24:
Line 25:
Line 26:
Line 27:
Source File: c:\users\alokp\onedrive\documents\visual studio 2015\Projects\Shopping Cart\Shopping Cart\views\web.config Line: 25
This is the new error I am getting.The database shop gets created but no tables or views or sp are seen.Please help.I am new to EF
I have a feeling you are missing some assembly information perhaps you should first fix the packages with Nuget
So where’s this step by step tutorial? I don’t see it.
Sir I am new to this.
Sir I am getting this error
Server Error in ‘/’ Application.
The model item passed into the dictionary is of type ‘MvcAffableBean.ViewModels.ShoppingCartViewModel’, but this dictionary requires a model item of type ‘MvcAffableBean.Models.ShoppingCart’.
I need it urgently so please reply as soon as possible.
I think you have not created the ShoppingCart Model inside models folder
https://github.com/shakeelosmani/MvcAffableBean/blob/master/MvcAffableBean/Models/ShoppingCart.cs
No sir,I have created ShoppingCart.cs inside models folder still I am getting that error.
even when I am clicking on any of the category,I am getting this error
HTTP Error 404.0 – Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
register login and logout is working fine.
whenever I am clicking on any category it is coming HTTP Error 404.0 – Not Found
I have StoreFront controller with index method still its not coming.
Please suggest something and reply soon.
Detailed Error Information:
Module ManagedPipelineHandler
Notification ExecuteRequestHandler
Handler System.Web.Mvc.MvcHandler
Error Code 0x00000000
Requested URL http://localhost:56734/StoreFront/Index/1
Physical Path c:\users\rd\documents\visual studio 2015\Projects\OnlineBookstoreHIT\MvcAffableBean\StoreFront\Index\1
Logon Method Forms
Logon User rd
Request Tracing Directory C:\Users\rd\Documents\IISExpress\TraceLogFiles\MVCAFFABLEBEAN
Detailed Error Information:
Module ManagedPipelineHandler
Notification ExecuteRequestHandler
Handler System.Web.Mvc.MvcHandler
Error Code 0x00000000
Requested URL http://localhost:56734/StoreFront/Index/1
Physical Path c:\users\rd\documents\visual studio 2015\Projects\MvcAffableBean\MvcAffableBean\StoreFront\Index\1
Logon Method Forms
Logon User rd
Request Tracing Directory C:\Users\rd\Documents\IISExpress\TraceLogFiles\MVCAFFABLEBEAN
Sir please reply soon…
Please explain what do you mean by this how can i do it Populate the required partial views for the Cart and Logon section on the navbar and What to do with migrations i have no idea and lastly Add the footer JavaScript on the _Layout file please also how to add.
This is an owsum tutorial..
Thanks Alot
All that you are looking for is part of the project source code, look for _Layout file in views. There is an ajax interaction for getting the cart items into the navbar. Also migrations are nothing but revision history about the changes to the data model. When you are starting the project you can clean the migrations folder and start over
My categories and product database was empty that’s why it was giving 404 error.Its resolved now.
sir, I want to now where username and password are being stored from registration form??
Good to know your problem is solved. ASP.net identity is handling that and it is being stored in a local db inside project folder app_data i guess
In this example You have Hard coded the category list (http://localhost:8257/StoreFront/Index/1)
I want to list the real Category List from the Database in the http://localhost:8257/StoreFront/Index/1
How can I do that ??
I purposely did that to make it rather easy. Good question though and it is quite simple to achieve what you want. First in the home controller index action query the database, something like below:
private MvcAffableBeanContext db = new MvcAffableBeanContext();
Then in index action:
return View(db.Categories.ToList());
Now in the Home index view:
@model IEnumerable<MvcAffableBean.Models.Category>
Then loop over categories:
@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.Name)
//link can be like this:
@Html.ActionLink(“Details”, “Details”, new { id=item.Id })
// or like this
<a href=”localhost:8257/StoreFront/Index/@item.Id”>@item.Name</a>
}
Offcourse now you have to dynamically use the images, depending on what category it is: you can store a image path in db or even look up in view:
if(item.Name == “Dairy”){
<img src=”dairy.png” />
}
you get the idea.
i got error ‘Sequence contains no matching element’ on code
int? count = (from cartItems in db.Carts where cartItems.CartId == ShoppingCartId select (int?)cartItems.Count).Sum();
I don’t Know what happened but here is how I did it:-
1) I downloaded the project from github.
2) I unzipped the project and opened that project in visual studio 2017 RC.
And Here is what happened when I tried to open in google chrome
1) I got 15 Errors and 28 warnings.
2) Some errors are as follows:-
i) CS0246 C# The type or namespace name ‘Controller’ could not be found (are you missing a using directive or an assembly reference?)
ii) CS1656 C# Cannot assign to ‘Count’ because it is a ‘method group’
iii) CS0030 C# Cannot convert type ‘method’ to ‘int?’
And all the Problem is from shoppingCart.cs page
Please tell me what is happening and what should I do to make it work. Since I am new to all MVC it would be easy for me if you would tell me step by step what to do now
All I can think of is Remove the old Assembly references and use Nuget to add System.Web.Mvc
Other than that you should Google around I guess with the 2017 version the web project does not have MVC reference DLLs pulled
Dear Shakeel,
For this proj., I want the name of the tables and their structure…
Shakeel, My name is Bashir, and my age is 63 yrs. I am interested in MVC.so I am creating this project from my home…
Bashir Ansari.
9833884922
Please help me in resolving this error:—-
Error The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly C:\Users\subrat mohapatra\Desktop\github\MvcAffableBean\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///C:\Users\subrat mohapatra\Desktop\github\MvcAffableBean\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. MvcAffableBean
Deleting the project\project\packages directory should solve build problems since NuGet fetches the packages automatically on build.
sir when I am running this project I am getting this sqlexception
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)
sir I have already added connection string in web.config
I am using visual studio2015.Sir its urgent.Please reply asap.
Looks like SQL Server is either not running or is not configured to be accessible at the string that web.config points to. Best way is use database explorer in Visual Studio and connect to the DB and then copy the connection string once able to successfully connect
Yes sir my sql server was not running.It is working fine after changed its status to started in service panel.
Thank you.
Great Project!!! I have one issue. The “Remove From Cart” doesn’t seem to work. I noticed the href=”” is empty. Can you provide some guidance? Thanks!
Hi John, the link is empty because the action is linked to JavaScript based ajax. https://github.com/shakeelosmani/MvcAffableBean/blob/master/MvcAffableBean/Views/Shared/_Layout.cshtml the script is in that page. You just open JavaScript console and see when you click on remove what happens , may be you have a JavaScript error and fixing that should fix it.
Awesome, didn’t have the javascript in my layout file. Thank you for the help!!!
I wasn’t able to open this with a visual studio 2015 😦
Hi Good Work.
The migration of the Shopping cart doesnt work though.
E.g. if i register and login with a user and adds a couple of items then logouts and login again. My earlier items are not stored.
That’s a retrieve cart functionality and it is not implemented is not that hard though, store the session cart into db on Logout and then when login check if a session cart was stored and add that to the current session cart simple.
Hi
I have downloaded the source file from github but I fount some errors while running the project so please would you help me by providing steps in order to run the project. thank’s
Great project!
I want my users to add products. So I have to keep membership informations in my database. But there is no membership table created. But I register and log in successfully. How can I save membership table? Therefore I can make relationship with products.
The way it works is ASP.net identity service provider creates a local DB look inside project folder and you will find inside app_data the DB file for registration and login then you can build a model for the same and use from entity framework
not able to find database
i would like to know how to add a drop down of suppliers when the user want to creat a new product ?!?!??
Thank’s, I managed, you helped me! it’s like to add category..
How can I add a image for every product?
I wan’t to add “string ImagePath” to the model.
how to Implemment this? (How to desplay it in the view ect..)
Getting this error
“Error 14 The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly C:\Users\Yasa\Desktop\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///C:\Users\Yasa\Desktop\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. MvcAffableBean”
when running the project.
any one can resolve this?
delete the packages directory completely and let nuget download them. You will be good to go
Where is database file??
I have made it clear in the blog post that there is no database file. Entity Framework will build the database for you. Read the blog thoroughly you will get the idea.
I have downloaded the source file from github but I fount some errors while running the project so please would you help me by providing steps in order to run the project
Check the update section in the blog post. If you are running into the same problem, those steps will fix your problem. If anything else write about the problem clearly. If I could help I would.
it does not recognize the packages???
and i don’t know how to run the project??
I need some help. I tried to cahnge the “add to cart” butten so that the user can input a number.
For example, He wants to buy 10 times a specific album.
I tried this: (inside the @foreach (var item in Model) )
@using (Html.BeginForm(“AddToCart”, “ShoppingCart”, new { id = item.ProdId, HowMany = “num” }))
{
}
but that was not work. How can I pass the 2 parameters??
Please help me
the project run with me with out CSS and Scripts
how can i insert it to the project??
sir while register ,it doesnot accept any alphanumeric characters as password.It is only accepting special characters.I guess its a problem related to membership.
How can i resove this problem??please reply
Hi,
I am finding it hard to Login or register. Please, can someone explain to me how I can login or register witin the Application. I have been able to make it Run but cannot login to the backend.
Hey Chris, there is no administration backend on this application. I just didn’t build it. However, the login and registration is for checkout. You can easily build an administrative backend if you want. Since we already have a Product model, category model, orders model etc, you just have to create the CRUD controllers by automatically generating them using Visual Studio. Afterwards you can decorate it with Authorize annotations to lock them down and even set the roles to administration. This would be a fun little exercise and would contribute to deeper learning.
Thank you Champ 🙂
and i Cannot find tables for storing username and password stuff 🙂
The way it works is ASP.net identity service provider creates a local DB look inside project folder and you will find inside app_data the DB file for registration and login then you can build a model for the same and use from entity framework if you wanna store it in your database instance.
I pointed , web configuration in my existing database and other tables are created as expected but the identity tables are not created as I usually create those tables in dedicated existing database instead of app_data . thanks for the reply 🙂
Ur really awesom man ,,,ur helping a lot for freshers like us ,,god bless u ,keep doing good work….
I get this error when I try and build in VS 2017
Severity Code Description Project File Line Suppression State
Error The specified task executable location “C:\Projects\GitHub\MvcAffableBean\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\csc.exe” is invalid. MvcAffableBean
how can add more in home index.cshtml
div row
I don’t understand what do you mean here. If you meant to add more HTML content or more rows of items, just add them using the Products Controller
Where is the Admin modula???
there is no admin module, you can easily build it
Hello,
great post and project!
I have a question regarding this MVC Project.
I do not want that EF create my DB as above described, I mean: no “code first” option but “database first” option without any migrations etc…
Can I use your project from github (I have already downloaded from github) and change only the connection string to my localDB and run the project? But I have no ERM or Database Sructrure to build my own DB wich is more important for me! Do you have a small Database Diagramm or ERM with your tables and relations so that I can adapt this to your project?
Thanks in advance and kind regards,
George
I do not have one, but you can use my code and generate the db then make a db design using SSMS. Share with us too 🙂
Hi,
OK I have done this, here you have the db design in SSMS
Sorry I can not upload a image file with the DB Design
Usually it’s not recommend to upload binary image rather store path in the database and use it
By the way, how can I do the LogOn and Register Data to save on my local Database?
As you have written above to another user
:—“your comment” —
The way it works is ASP.net identity service provider creates a local DB look inside project folder and you will find inside app_data the DB file for registration and login then you can build a model for the same and use from entity framework —“your comment ends” —
I have build your project without using any Migrations I have created the local DB from my one. Does it means I have to create in my local DB a table Users and there to save the registered Users ?
Thanks for your help
George
Yes you can create a model and controller and follow the same principles
Sorry if i’m too dumb but in source code, you have DAL folder, but I dont see which step i need to add it into project
First I added all class to Models, but there are not MvcAffableBean.DAL so MvcAffableBeanContext was invalid, then I added folder DAL and its class but VS could not recognize DbSet
I’m using VS 2017. Which step was wrong 😦
if I take a guess, use NuGet package manager and install Entity Framework
nice tutorials
Error 14 The specified task executable location “D:\MvcAffableBean-master\MvcAffableBean-master\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\csc.exe” is invalid. MvcAffableBean
this error occur how to solve it plzzzz tell me
Your system is missing the required .net version, i believe either you are using a latest version of Visual Studio, then build the app yourself, else try to update the .net framework on your computer
thanks for code, i have downloaded code and i have followed the instructions and my code is successfully build the code but when creating new registration i am getting error “Unable to connect to SQL Server database” near “Membership.CreateUser(model.UserName, model.Password, model.Email, “question”, “answer”, true, null, out createStatus);” and everything working well for Products, categories……..
The ASP.net identity provider creates a local db users table, if you do not have localdb installed with same version it wont work. Inside the web.config default connection factory, add a parameter and use it to point to your main db connection source or localdb as below if you have one
thanks for reply after create the migrations, in database all tables are created but in customer table only id column is created. why it is creating only one column.
i am using VS2015, EntityFramework 6.13, sql server 2014
It would be difficult to tell, without actually looking. Look through model code, double check migrations file, there may be clue in there why that is happening
hi. There is a folder util that has the state list but it has not been used anywhere. what was its purpose
I think it is used to populate the state drop-down in checkout address
I just downloaded code from github and pagea are loading fine. I couldn’t see any products when i click on categories. Can you share the script to just load some products
There is no script to load products. Just use a initializer in your app run or create some categories and products by scaffolding those controllers with create action. In fact there is already create action for categories controller and products controller. Just use them .
Hello, I am not able to understand what has to be done, I execute the program it gives a sequence of error, can someone give me a detailed step by step do it has to be done?
or the project updated and ready to run?
thank you!
is there this tutorial step by step videos that can i follow to build this project
link from the installation video?
Please!
Thank a lot for such a nice project! Really helps!!!!
How can i download asp.net e commerce website project with complete source.
Cannot Download complete source here
https://github.com/shakeelosmani/MvcAffableBean
Error: There is a problem connecting securely to this website.
Can you fix it?
Thanks
Kang
nice article for website design company in mumbai
can please provide database script.
Hi can you help me setup my controllers
about the modal classes, what to select?
products not created? can anyone share runable source ?
i am trying this code for dropdown list but it gives error is that value cannot be null
code is
@Html.DropDownListFor(p => p.StateId, new SelectList(Model.StateDrpList, “StateId”, “StateName”), “– Select State Name –“, new {@onchange = “FillCity()”, @class = “form-control” })
@Html.ValidationMessageFor(p => p.StateId)
Instead of SelectList, use SelectListItem.
i m getting this error : The “Microsoft.CodeAnalysis.BuildTasks.Csc” task could not be loaded from the assembly C:\Users\Developer\Documents\New folder\MvcAffableBean\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly ‘file:///C:\Users\Developer\Documents\New folder\MvcAffableBean\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
I have done project set but i m trying to register its not happening. Please resolve my issue.
I had setup project database also ccreated but Registration not happed please resolve my issues.
Sir where is database script which i can install in my sql server Please help me
There is no database script, Entity framework will create it for you, please read the blog
Is there any licence concerns for this project to use?
Also, is payment option included in the project?
There is no license concern, please use it as you like. No payment option is configured but I will highly recommend razorpay APIs they are great.
Hello ranatigrina2002, So i can run the application, but is there a way to make register and login works?
It already works. follow the tutorial text.
Thank you.. i will find out the problem
@ranatigrina2002 i wondering RegisterModel, I can’t found it at Models folder. Where is it come from?
Hi there,
This project is great, but I’m struggling to separate the membership and data sources, which is what I’d be trying to do in the real world.
I’ve managed to update my connection to a “real” SQL server, and happily can add products to the cart, etc.
BUT, I cannot register a user if that is the connection. Similarly, if I change my connection to localDb, it will create everything locally, which I don’t want.
I understand that I’d probably need to create a second connection string key, but I don’t see how that is applied using the context in the example. It seems that most of the membership classes such as RegisterModel are hidden, so how do we separate the membership from the actual business data layer?
Thanks!
Graham
Great question. Take a look at this https://stackoverflow.com/questions/11801471/defaultconnection-and-membership-what-is-the-connection-between-localsqlserver
Hi I am facing the below error
Could not find a part of the path ‘F:\SmartStoreNET-3.x\SmartStoreNET-3.x\src\Presentation\SmartStore.Web\bin\roslyn\csc.exe’.
Hi.
Thank you for the tutorial was a great help with getting started. I was wondering if you could help, I want a more detailed product view once you click on the product.
Any reference or tutorial will be greatly appreciated.