I want to fetch information from a table with EF [closed]

2

I have the following form code:

@model Domain.Entities.Tabela1
@using WebUI.HtmlHelpers
@using WebUI.Extensions
@{
    ViewBag.Title = "Tabela";
    Layout = "~/Views/Shared/_Master.cshtml";
}
<article ng-app="registrationModule">
    <section>
        <div>
            <div ng-controller="Tabela1FormController">
                <form class="form" name="tabela1Form" ng-submit="save(tabela1)" novalidate style="width: 700px; margin-left: auto; margin-right: auto;">

                    </div>

                    <div>
                        <div>
                            <label for="name">Nome:</label>
                                <input type="text" name="name" ng-model="tabela1.name" />
                        </div>
                    </div> 
//Aqui eu gostaria de busca a informação
<input type="text" name="name" ng-model="tabela2.medida" /> 

My Entities Table1:

[Table("Tabela1")]
    public class Tabela1
    {
        [Key]
        public int tabela1ID{ get; set; }

        //Strings
        [Required(ErrorMessage = "O campo \"Nome\" é obrigatório")]
        public string Name { get; set; }
        [Required(ErrorMessage="O campo \"Unidade de Medida\" é obrigatório")]
        public string medida{ get; set; }


        //Collections
        public ICollection<Coleçao> campo { get; set; }


        public tabela1()
        {
            campo= new HashSet<Coleçao>();   
}        

Entitie table2:

public class tabela2
    {
        public static tabela2 Default = new tabela2();

        [Key]
        public int tabela2ID { get; set; }
        public string Unit { get; set; }
        [Required(ErrorMessage = "Digite um símbolo da unidade de medida")]
        public string Symbol { get; set; }

    } 

ListView table1

 public class tabela1ListViewModel : PaginationViewModel
    {
        public IEnumerable<tabela1> tabela1{ get; set; }
    }

My control:

  public ActionResult Newtabelar()
    {
        return View("tabelaForm");
    }

[Permission(Path = IndicatorPath.tabela, Permission = PermissionType.ReadWrite)]
public ActionResult EditItabela(int tabelaid, bool onlyRead = false)
{
    var tabela = tabela1Repository
        .tabela1
        .Include(x => x.tabela3)
            .Include(x => x.tabela4)
            .Include(x => x.tabela5)
            .Include(x => x.tabela6)
        .FirstOrDefault(x => x.tabela1id == tabela1id);

    ViewBag.OnlyRead = onlyRead;

    return View("tabela1Form", tabela);
}

Well, the table1 one it looks ok, but the table2 want to play the fields that it has in a select in the form it does not search, my view was made with angular, how should I proceed to solve this problem. Thank you in advance.

    
asked by anonymous 30.06.2017 / 13:07

1 answer

3

You can use a ViewModel:

public class ViewModel1
{
   public Tabela1 tabela1 { get; set; }
   public Tabela2 tabela2 { get; set; }
}

Action:

public ActionResult Index()
{
    var viewModel = new ViewModel1();

    // Preencha as propriedades do objeto viewModel1

    return View(viewModel);
}

From here you can use model table2 in your View.

    
30.06.2017 / 13:57