ASP.net MVC step by step complete E-commerce tutorial

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

asp_net_mvc_project_strcture

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

Home Page desktop view
Home Page desktop view
Home Page Mobile view
Home Page Mobile view
Mobile navigation
Mobile navigation

cart_desktopcart_mobilestore_front_mobile

store_front_desktop

checkout_requires_login

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

  1. 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
  2. In the Models folder add all the domain classes as found in the GitHub Models directory and build the project once
  3. Add Controllers one by one scaffolding from the Model and with Entity Framework
  4. Add Views via right clicking on the controller action from the scaffold
  5. Create the shopping cart view models as defined in the ViewModels folder from the GitHub project
  6. 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
  7. Populate the required partial views for the Cart and Logon section on the navbar
  8. Create the checkout controller
  9. Copy the Accounts controller from the GitHub project
  10. Add the footer JavaScript on the _Layout file
  11. Import the images and keep the folder structure same
  12. 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

172 thoughts on “ASP.net MVC step by step complete E-commerce tutorial

  1. wow, the source code is complete and well commented I liked it. In fact based on this I created my school project. Thank you.

  2. 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?

  3. 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

  4. 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. 😦

  5. 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.

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. i can’t access your files when ever i click on download link “unable to connect” message on browser showned.

  12. 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

  13. 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

  14. 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.

  15. 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

  16. 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.

  17. 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.

  18. 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

  19. 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…

  20. 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

  21. 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??

    • 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.

  22. 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();

  23. 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

  24. 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

  25. 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

  26. 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.

  27. 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!

  28. 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.

  29. 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

  30. 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

  31. 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..)

  32. 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?

    • 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.

  33. 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.

  34. 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

  35. 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

  36. 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.

    • 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 🙂

  37. Ur really awesom man ,,,ur helping a lot for freshers like us ,,god bless u ,keep doing good work….

  38. 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

  39. 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

  40. 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

  41. 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 😦

  42. 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

  43. 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

  44. 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

  45. 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 .

  46. 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!

  47. 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)

  48. 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.

  49. 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

  50. 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’.

  51. 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.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.