1

SO I have an entity called product as follow:

public class Product
    {
        [HiddenInput(DisplayValue=false)]
        public int ProductID { get; set; }
        public string ProductName { get; set; }
        [DataType(DataType.MultilineText)]
        public string ProductDescription { get; set; }
        public decimal ProductPrice { get; set; }
        public string Category { get; set; }
        public string SubCategory { get; set; }
    }

I have another class called EFProductRepository which is derived from another class called IProductRepository as following:

public class EFProductRepository : IProductRepository
    {
        private EFDbContext context = new EFDbContext();
        public IEnumerable<Product> Products
        {
            get { return context.Products; }
        }
    }

Then in my controller action Index i have this:

public ViewResult Index()
        {
            return View(repository.Products);
        }

and a view for index which list the data in a table, SO the question is how can i implement the DataTable client side to this piece of code? i tried this here jQuery Datatable with MVC 5 and Entity Framework but no luck unfortunately. Any help is appreciated, Regards.

3
  • 1
    I assume the datatable plugin expects data in JSON format. convert your context.Products to JSON format ( may be after mapping them to a list of view models which has properties which the plugin is looking for) Commented Apr 12, 2016 at 15:47
  • @Shyju any hint on how to change it to JSON? Commented Apr 12, 2016 at 16:02
  • there is a Controller.Json method you can use. Commented Apr 12, 2016 at 16:03

1 Answer 1

1

If you don't want to convert your object to JSON and mess with all that controller customization, I would suggest checking out this data table that I use in my MVC 5 projects. https://gridmvc.codeplex.com/ This will give you a lot of functionality you may want on the front end anyways, and it just directly binds to a list of objects.

There are easy getting started guides under the documentation.

Good luck

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like a good alternative, I can't accept this as answer but i up voted it. I really need to get on DataTables ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.