none
How to pass ids of multiple Checkboxes selected in an Index View to the Controller? RRS feed

  • Question

  • Hello,

    I am developing an application in ASP.NET MVC using Razor views with Entity Framework. In my Index view, for each record, I also provide a checkbox for the purpose of validation by way of <input id="@item.Id" type="checkbox" class="checkbox" name="Validation" value="true"/> so that each checkbox has id corresponding to a given record. 

    What I want to achieve is to pass all the ids of various numbers of Checkboxes that a user may select say 10, 15 or more from the list to the controller on click of a button provided for validation.

    Please help me solve this.

    Regards,

    Arun

    Monday, March 26, 2018 1:54 AM

Answers

All replies

  • You don't have EF issues. You have MVC issues concerning views, controllers and viewmodels.

    I'll give you this to think about. And then, you can post to the MVC forum in ASP.NET forums.

    http://forums.asp.net/

    https://www.c-sharpcorner.com/UploadFile/56fb14/understanding-separation-of-concern-and-Asp-Net-mvc/

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/overview/understanding-models-views-and-controllers-cs

    <copied>

    An MVC model contains all of your application logic that is not contained in a view or a controller. The model should contain all of your application business logic, validation logic, and database access logic. For example, if you are using the Microsoft Entity Framework to access your database, then you would create your Entity Framework classes (your .edmx file) in the Models folder.+

    A view should contain only logic related to generating the user interface. A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control). Everything else should be contained in the model.+

    In general, you should strive for fat models and skinny controllers. Your controller methods should contain only a few lines of code. If a controller action gets too fat, then you should consider moving the logic out to a new class in the Models folder

    <end>

    Monday, March 26, 2018 9:52 AM
  • Hello DA924x,

    I got the solution at the following link:

    The Solution

    However, I thank you so much for responding.

    Regards,

    Arun.

    • Marked as answer by ArunKhatri Monday, March 26, 2018 5:47 PM
    Monday, March 26, 2018 5:29 PM