title: In an ASP.NET Core MVC view, how can I access properties of the current model?
body: <p>I am making a basic CRUD application in ASP.NET Core MVC that allows users to interact with a number of TV channels. When the user clicks on the "Edit" button for a particular channel, this code is run:</p>
  
  <pre><code>&lt;a asp-action="Edit" asp-route-id="@Html.Raw(channel.ID)"&gt;Edit&lt;/a&gt;
  </code></pre>
  
  <p>Next, the user is taken to the "Edit" view. This view contains a form with every editable property. Here is an example of the "Description" field:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label asp-for="Desc" class="col-md-2 control-label"&gt;&lt;/label&gt;
      &lt;div class="col-md-10"&gt;
          &lt;input asp-for="Desc" class="form-control"/&gt;
          &lt;span asp-validation-for="Desc" class="text-danger"&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This field should contain the existing description, so that the user does not have to remember what it is. How can I pass this information from the "Index" view to this one?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Per request, here is my full controller:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Http;
  using Microsoft.AspNetCore.Mvc;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Text;
  using System.IO;
  using Newtonsoft.Json;
  using TV_Channel_Manager.Models;
  using System.Text.RegularExpressions;
  
  namespace TV_Channel_Manager.Controllers
  {
      public class ChannelController : Controller
      {
          // GET: Channel
          public async Task&lt;ActionResult&gt; Index()
          {
              using (var client = new HttpClient())
              {
                  client.BaseAddress = new Uri("http://localhost:57412/");
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("Administrator:")));
  
                  HttpResponseMessage response = await client.GetAsync("config/v1/project/channels");
                  if (response.IsSuccessStatusCode)
                  {
                      string responseStr = await response.Content.ReadAsStringAsync();
                      // change keys so that they match props, and convert to object
                      List&lt;Channel&gt; channels = JsonConvert.DeserializeObject&lt;List&lt;Channel&gt;&gt;(responseStr.Replace("PROJECT_ID", "ProjID").Replace("common.ALLTYPES_DESCRIPTION", "Desc").Replace("common.ALLTYPES_NAME", "Name").Replace("servermain.CHANNEL_DIAGNOSTICS_CAPTURE", "CaptureDiag").Replace("servermain.CHANNEL_NON_NORMALIZED_FLOATING_POINT_HANDLING", "NonNormalizedFloatHandling").Replace("servermain.CHANNEL_UNIQUE_ID", "ID").Replace("servermain.CHANNEL_WRITE_OPTIMIZATIONS_DUTY_CYCLE", "WriteOptimDutyCycle").Replace("servermain.CHANNEL_WRITE_OPTIMIZATIONS_METHOD", "WriteOptimMethod").Replace("servermain.MULTIPLE_TYPES_DEVICE_DRIVER", "Driver").Replace("simulator.CHANNEL_ITEM_PERSISTENCE", "ItemPersistence").Replace("simulator.CHANNEL_ITEM_PERSISTENCE_DATA_FILE", "ItemPersistenceFile"));
                  ViewData["channels"] = channels; // pass object list to view
              }
          }
  
          return View();
      }
  
      // GET: Channel/Details/5
      public ActionResult Details(int id)
      {
          return View();
      }
  
      // GET: Channel/Create
      public ActionResult Create()
      {
          return View();
      }
  
      // POST: Channel/Create
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(IFormCollection collection)
      {
          try
          {
              // TODO: Add insert logic here
  
              return RedirectToAction("Index");
          }
          catch
          {
              return View();
          }
      }
  
      // GET: Channel/Edit/5
      public ActionResult Edit(int id)
      {
          return View();
      }
  
      // POST: Channel/Edit/5
      [HttpPost]
      [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Edit(long projID, string desc, string name, bool captureDiag, int nonNormalizedFloatHandling, long ID, int writeOptimDutyCycle, int writeOptimMethod, string driver, bool itemPersistence, string itemPersistenceFile)
      {
          using (var client = new HttpClient())
          {
              client.BaseAddress = new Uri("http://localhost:57412/");
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
              client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("Administrator:")));
  
              Channel newChannelObj = new Channel(projID, desc, name, captureDiag, nonNormalizedFloatHandling, ID, writeOptimDutyCycle, writeOptimMethod, driver, itemPersistence, itemPersistenceFile);
              // replace prop names with actual names
              string serialized = JsonConvert.SerializeObject(newChannelObj).Replace("\"ProjID\"", "\"PROJECT_ID\"").Replace("\"ID\"", "\"servermain.CHANNEL_UNIQUE_ID\"").Replace("Desc", "common.ALLTYPES_DESCRIPTION").Replace("Name", "common.ALLTYPES_NAME").Replace("CaptureDiag", "servermain.CHANNEL_DIAGNOSTICS_CAPTURE").Replace("NonNormalizedFloatHandling", "servermain.CHANNEL_NON_NORMALIZED_FLOATING_POINT_HANDLING").Replace("WriteOptimDutyCycle", "servermain.CHANNEL_WRITE_OPTIMIZATIONS_DUTY_CYCLE").Replace("WriteOptimMethod", "servermain.CHANNEL_WRITE_OPTIMIZATIONS_METHOD").Replace("Driver", "servermain.MULTIPLE_TYPES_DEVICE_DRIVER").Replace("\"ItemPersistence\"", "\"simulator.CHANNEL_ITEM_PERSISTENCE\"").Replace("\"ItemPersistenceFile\"", "\"simulator.CHANNEL_ITEM_PERSISTENCE_DATA_FILE\"");
              StringContent newChannel = new StringContent(serialized, Encoding.UTF8, "application/json");
  
              HttpResponseMessage response = await client.PutAsync("config/v1/project/channels/" + name, newChannel);
  
              if (response.IsSuccessStatusCode)
                  return View();
          }
  
          return NotFound();
      }
  
      // GET: Channel/Delete/5
      public ActionResult Delete(int id)
      {
          return View();
      }
  
      // POST: Channel/Delete/5
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Delete(int id, IFormCollection collection)
      {
          try
          {
              // TODO: Add delete logic here
  
              return RedirectToAction("Index");
          }
          catch
          {
              return View();
          }
      }
  }
  </code></pre>
  
  <p>}</p>