asp.net MVC - variable value is not updated -


the variable used in view not updated when changing value.

the following steps have done.

  1. i have declared variable in view.

  2. then changed variable value before rendering in view. updated.

  3. after rendered, have updated variable value immediately. view value not updated latest value.

here had confusion because string object. whenever value has been changed string, reference value should changed. why not changed in view.

<div class="col-md-6 col-md-offset-3">                 declare , update variable value                 @{                    string value="test value";                      if(true)                     {                           value="value has been checked once";                     }                      <div>                         @value                     </div>                     if(true)                     {                           value="again value has been checked once";                     }                  }             </div> 

output:

declare , update variable value value has been checked once 

please refer sample https://dotnetfiddle.net/glmbbk

as title implies ought use mvc. in controller declare model can send view. view able handle values given. can post values in model controller if wish handle them further.

controller

public actionresult myview(){  var model = new myviewmodel{    someproperty = "hello" } } 

model

[display(name = "greeting")] public string someproperty{get; set;} 

view

@html.labelfor(m => m.someproperty) @html.displayfor(m => m.someproperty) 

if want change whilst on view, depedning on nature of problem, use either form post controller or jquery/javascript alter variable.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -