asp.net mvc - Getting Data to Show up in My view -


i've got model , controller working, model not showing data inside view. ideas on doing wrong?

i have single model trying pass couple variables inside it.

i trying use html.viewdata.model.(variable name here). keep getting null exception though have hardset values in model.

any ideas

model

using system; using system.collections.generic; using system.linq; using system.web; using system.collections.generic; using system.componentmodel.dataannotations; using microsoft.aspnet.identity; using microsoft.owin.security;   namespace stuff {     public class bacnetmodel     {         private string _rmnum = "room number";         public string rmnum { { return _rmnum; } set{_rmnum = value;} }          private string _avres = "70";         public string avres { { return _avres; } set {_avres = value;} }          private string _bvres = "t";         public string bvres { { return _bvres; } set { _bvres = value; } }          private string _mvres = "o";         public string mvres { { return _mvres; } set { _mvres = value; } }     } } 

controller

public class peocontroller : controller     {          //set default values         private string avresult = "90";         private string bvresult = "t";         private string mvresult = "o";         private string rmnum = "room";          // get: peo          public actionresult peo(string bvresult, string avresult, string mvresult, string rmnum)         {              var model = new bacnetmodel             {                 avres = avresult,                 bvres = bvresult,                 mvres = mvresult,                 rmnum = rmnum             };              return view(model);         }          public actionresult getroomnumber(string roomnumber, ref uint bvinstance, ref uint avinstance, ref uint mvinstance, out string rmnum)         {             switch (roomnumber)             {                 case ("1b^1001^01"):                     rmnum = "1b^1001^01";                     bvinstance = 3000018;                     avinstance = 3000022;                     mvinstance = 3000040;                     break;                  case ("1b^1002^01"):                     rmnum = "1b^1002^01";                     bvinstance = 3000020;                     avinstance = 3000023;                     mvinstance = 3000042;                     break;                  default:                      break;             }             rmnum = "room";              var model = new bacnetmodel             {                 avres = avresult,                 bvres = bvresult,                 mvres = mvresult,                 rmnum = rmnum             };               return view(model);         }      } 

view

@using  stuff @using microsoft.ajax.utilities @model bacnetmodel  @{     viewbag.title = "";     layout = "~/views/shared/_layout.cshtml"; }  <h2> stuff(peo)</h2> <p>     stuff </p> <label>select room: </label> <!-- need add code loop through database , provide rooms.         need provide query called on page load.-->  <form action="/peo/getroomnumber">     <select id="roomlist">         <option value="1b^1001^01">1b^1001^01</option>         <option value="1b^1002^01">1b^1002^01</option>     </select><br/><br/>      <fieldset id="peofieldset">         <legend>room results</legend>         <label for="roomnumber">room number:</label>         <input id="roomnumber" readonly="readonly"/>@html.viewdata.model.rmnum<br>         <label for="rmsetpoint">room setpoint: </label>         <input id="rmsetpoint" readonly="readonly" />@html.viewdata.model.avres<br>         <label for="rmcode">room code: </label>         <input id="rmcode" readonly="readonly" />@html.viewdata.model.bvres<br>         <label for="rmocc">room occupancy: </label>         <input id="rmocc" readonly="readonly" />@html.viewdata.model.mvres<br>     </fieldset> </form>  <label>occupancy value</label> <select id="occvalue">     <option value="occupied">occupied</option>     <option value="unoccupied">unoccupied</option> </select> 

i'm not sure why using viewdata in view. use standard model binding rather. try following code in view:

<fieldset id="peofieldset">     <legend>room results</legend>     <label for="roomnumber">room number:</label>     <input id="roomnumber" readonly="readonly"/>@model.rmnum<br>     <label for="rmsetpoint">room setpoint: </label>     <input id="rmsetpoint" readonly="readonly" />@model.avres<br>     <label for="rmcode">room code: </label>     <input id="rmcode" readonly="readonly" />@model.bvres<br>     <label for="rmocc">room occupancy: </label>     <input id="rmocc" readonly="readonly" />@model.mvres<br> </fieldset> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -