0
votes

I have three tables in the name of Person and City and Evidence whose table has person a few columns including FirstName , LastName ,cityid (cityID), EvidenceID that id of the table (EvidenceID), the EvidenceID fields and the cityID are foreign keys, and to the id table City maps, Evidence connected

Now I want to have two combo boxes (tag) when I'm creating a new person, so that they can list them in place of the ID of the city and the id of the Evidence , and list them in the cowboy box.

Also, when editing, I want to know that when I go to the editing form, you can see the name of the city and the person's profile on the cowboys, and we can also see and edit the other cobblestones. please guide me.

[HttpGet] public ActionResult EditPerson(int id) { var q = (from a in db.Person where a.ID.Equals(id) select a).SingleOrDefault();

        if (q != null)
        {
            return View(q);
        }
        else
        {
            return RedirectToAction("ShowPerson", "Home");
        }
    }


    [HttpPost]
    public ActionResult EditPerson(Person per)
    {
        var q = (from a in db.Person
                 where a.ID.Equals(per.ID)
                 select a).SingleOrDefault();

        q.FirstName = per.FirstName;
        q.LastName = per.LastName;
        q.UserName = per.UserName;
        q.EvidenceID = per.EvidenceID;
        q.Mobile = per.Mobile;
        q.Stutus = false;
        q.CodeMelli = per.CodeMelli;
        q.CityID = per.CityID;
        q.Address = per.Address;
        q.Access = per.Access;
        q.Email = per.Email;
        q.Image = per.Image;

        db.Person.Attach(q);
        db.Entry(q).State = System.Data.Entity.EntityState.Modified;
        db.SaveChanges();

        return RedirectToAction("ShowPerson", "Home");
    }


    [HttpGet]
    public ActionResult CreatePerson()
    {

        return View();
    }


    [HttpPost]
    public ActionResult CreatePerson(Person per)
    {
        Person p = new Person();

        p.FirstName = per.FirstName;
        p.LastName = per.LastName;
        p.UserName = per.UserName;
        p.EvidenceID = per.EvidenceID;
        p.Mobile = per.Mobile;
        p.Stutus = false;
        p.CodeMelli = per.CodeMelli;
        p.CityID = per.CityID;

        p.Address = per.Address;
        p.Access = per.Access;
        p.Email = per.Email;
        p.Image = per.Image;

        db.Person.Add(p);
        db.SaveChanges();

        return RedirectToAction("ShowPerson", "Home");
    }

code in view edit :

        <div class="form-group">

@Html.LabelFor(model => model.CityID, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor(model => model.CityID, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CityID, "", new { @class = "text-danger" })

        <div class="form-group">

@Html.LabelFor(model => model.EvidenceID, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor(model => model.EvidenceID, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.EvidenceID, "", new { @class = "text-danger" })

1

1 Answers

0
votes

Your question is not being understood but what you need is a dropdownlist from three different models as i'm guessing...

try this in your own domain:

var dataForDL = _db.ModelName.Select(a => new
                {
                   Text = a.PersonName +" "+ a.Evidence.Name +" "+ a.City.CityName,
                   Value = a.Id
                }).ToList();
ViewBag.DropdownListForModel = new SelectList(dataForDL, "Value", "Text");

In the view.cshtml

@Html.DropDownList("DropdownListForModel", null, "-- Please Select Something --", htmlAttributes: new { @class = "form-control" })