What is the scope of variables on an ASP.NET MVC page?

Asked

Viewed 77 times

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>

Containing 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 kind of drew it like layout:

Layout paint

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

How to do this?

How the variable scope works in this case?

And if there’s any way I can return the value of partial to the view main and the view main to the partial?

1 answer

3


In his partial view you need to create a model to receive the object that is passing on view main, something like that:

@model SimularViewModel

I put in the Github for future reference.

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

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

I have never tried to return a value to the main view, but this seems wrong to me, probably this partial view is doing more than just presenting data that is its function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.