What is the scope of the variables in a page with ASP.NET MVC?

3

I have a view layout :

<div>
    <h1>Pagina Principal<h1>
</div>
<div>
    <h3>Simular<h3>
</div>
<div class="row">
    @{Html.RenderPartial("Partials/Teste/Simular", new SimularViewModel(cpf: Model.Cliente.Cpf, idCampanha: Model.Ocorrencia.IdCampanha));}
</div>
<div>
    <h3>opções<h3>
</div>
<div class="row">
    @{Html.RenderPartial("Partials/Cadastro/_Opcoes", new CadastroViewModel(cpf: Model.Cliente.Cpf, idCampanha: Model.Ocorrencia.IdCampanha));}
</div>

That contains 2 partials views :

Simulate

<div>
    <label>texto</label>
    <label>texto</label>
</div>
<div>
    @Html.ActionLink("Ir para Simulação", "Index", "Simular",
          new { cpf = Model.Cpf, origem = ViewBag.Origem},
          new { @class = "btn btn-brand float-right btn btn-brand float-right" })
</div>

Register

<div>
     @Html.DropDownListFor(model => model.Status, Model.StatusOcorrencias.Select(so => new SelectListItem() { Text = so.Status, Value = so.Id.ToString() }), "Selecione", new
     {
         @class = "form-control m-input m-input--square",
         @id = "dllStatus",
         style = "width: 100%"
      })
</div>
<div>
     @Html.TextAreaFor(x => x.Observacao, new { @class = "form-control m-input", maxlength = "500" })
</div>

I drew more or less how the layout is:

I need to pass the information of the fields that can be populated by the user in the partial view 2 Cadastrar , to the ActionLink button of the partial view 1 Simular .

How to do this?

How does the scope of the variable work in this case?

And if I have to return the value of the partial for the main view and the main view for the partial in>?

    
asked by anonymous 16.11.2018 / 17:35

1 answer

3

In your partial view, you need to create a model to get the object you are passing in the main view, like this:

>
@model SimularViewModel

Then you will have a template available in this new view.

The scope is equal to a normal code, each view is like a function.

I have never tried to return a value for the main view, but this seems to me wrong, probably this partial view is doing more than just submitting data which is the function of it.

    
16.11.2018 / 18:21