简体   繁体   中英

How can I use Create with filtering in MVC 5 CRUD operation?

I have a Customer table and Approval table as shown below. I created my Customer Controller and Views and its working. In CustomerView.cshtml the user cannot see the CustActive columns.

Now I need to create an ApprovalController with filtering. In Approval.cshtml page when I click on Create button I need to load the ComboBox that contains a Customer Name and Surname where CustActive = False . Then, when I select a customer from the ComboBox, I want to create columns such as CustId , ManagerName and ManagerSurname that will be activated for editing. After the edit I need to save the data for the Approval Table and insert true value for CustActive columns in Customer Table.

How can I do that?

CUSTOMER TABLE

CustId
Name
Surname
CustActive

APPROVAL TABLE

AppId
CustId
ManagerName
ManagerSurname

Kind Regards

Ok you need insert in APPROVAL TABLE costumer properties yes? Now after you created costumer you have define active as false and this is ok, after this you have write your APPROVAL controller like this:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "AppId,CustId,ManagerName,ManagerSurname")] Approval approval, string id)
{
var costumer = await db.Costumers.SingleAsync(x => x.CustId == id);
if (ModelState.IsValid)
{
    approval.CustId = id;
    CUSTOMER model = new CUSTOMER();
    model.CustActive = true;
    db.Entry(model).State = EntityState.Modified;
    db.Categories.Add(category);
    await db.SaveChangesAsync();
    return RedirectToAction("Index");
}

return View(approval);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM