0

so on my get Edit controller i have the following:

public ActionResult Edit(string id)
    {
        using (ISession session = NhibernateHelper.OpenSession())
        {                
            var site= session.Get<Sitios>(id);                            
            return View(site);                
        }            
    }

Which works for bringing my normal textfield properties from that specific site, BUT where im having the problem where im stuck at is when i want to bring in dropdown list in it as well, on the Create action i solved that by using this code:

//GET: Sitios/Create
    public ActionResult Create()
    {

        using (ISession session = NhibernateHelper.OpenSession())
        {                
            var deptos = session.Query<Departaments>().ToList();

            var SiteCopy =new Sitios
            {
                Departaments = deptos                
            };
            return View(SiteCopy);          
         }

The model part of that specific list is:

 public class Sitios
{
//more code       
   public virtual List<Departamentos> Departamentos { get; set; } 
}

And the view for Create action i used which is what i would like to be able to use on my edit view as well is

<div class="form-group">
    <label class="control-label col-md-2"> Departament </label>
    <div class="col-md-10">
        @Html.DropDownListFor(model => model.id_departamento, new SelectList(Model.Departamentos, "id_departamento", "description")
    </div>
</div>

So in summary i would like to see if its possible to use the below code which works fine for bringing the string properties of that specific site PLUS add the dropdown in it as well.

public ActionResult Edit(string id)
    {
        using (ISession session = NhibernateHelper.OpenSession())
        {                
            var sitio = session.Get<Sitios>(id);                            
            return View(site);                
        }            
    }

Thanks!

  • Not unless your instance of `Sitios` already has the `Departamentos` property fully populated. But in anycase, you should not be using data models when editing. Use a [view model](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc) –  Dec 13 '16 at 02:30
  • @StephenMuecke So create a view model specifically for this with only the required properties and populate the list on that view model and use it afterwards for this editing action? – Melvin Chinchila Dec 13 '16 at 02:36
  • That's the recommended approach :) –  Dec 13 '16 at 02:37

0 Answers0