Haminteu
Haminteu

Reputation: 1334

Checkbox Table to database MVC

I have a model like:

public class MasterDoc
{
    [Key]
    public int MasterID {get;set;}
    public string documentnumber {get;set;}
    public string oYear {get;set;}
    public bool isReady {get;set;} = 1
}

public class DocList
{
    [Key]
    public int DocListID {get;set;}
    [ForeignKey("MasterDoc")]
    public int MasterID {get;set;}
    public MasterDoc MasterDoc {get;set;}
    public DateTime? OrderDate {get;set;}
}

So the scenario is, I want to have a list (table) of MasterDoc with Checkbox on the table. When User check the checkbox, then user click a submit button. It will create a new record on DocList table, only MasterID value add to it. Also, the isReady column on MasterDoc table is updated into 0 or false.

Currently, I've a controller like:

public ActionResult Index(string xYear)
{
    var masterDocs = db.MasterDocs.Where(c => c.Year == xYear);
    return View(masterDocs.ToList());
}

Upvotes: 0

Views: 98

Answers (1)

Dileep Sreepathi
Dileep Sreepathi

Reputation: 254

In your View, First get the Model properties which is in List type, then using below code display the table

foreach(List<Masterdoc>)
{
//table along with checkbox
}

Then on submit button click , pass the checkbox value along with the masterdoc id to the Controller (here create another action method for Form Submission)

You can Create the stored procedure for the Record insertion based on the MasterId Consume the created procedure in the Form submission action method.

Upvotes: 1

Related Questions