0
        public ActionResult Create()
        {
            try
            {
                var Group = GroupRepository.FindAllGroups();
                ViewData["Group"] = GroupRepository.FindAllGroups();
                ViewData["Feature"] = FeatureRepository.FindAllFeatures();
                DataTable dt = FeatureRepository.GetAllFeatures();

                // TODO: Add insert logic here
                Group group = new Group()
                {
                    dtm_CreatedDate = DateTime.Now,
                    int_CreatedBy = 1

                };
               return View(group);

            }
            catch
            {
                return View();
            }
        } 

I want to send the datatable as well as the group object to the view. how will i do that

1 Answer 1

4

Create new specific class, that will keep the Group object as member and any objects you need to use in View

public class MySpecificViewClass
{
    public Group Group;
    ...
}

and after this specify this class instance as View argument

return View(new MySpecificViewClass { Group = group, ... } );
Sign up to request clarification or add additional context in comments.

2 Comments

+1, you beat me to it, just expose the datatable as a property of MySpecificClass
Not really, I wouldn't do it that way. Rather copy it to something more generic like a List or IEnumerable. DataTable feels so ADO.NET and WebForms, just my 2 cents..

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.