简体   繁体   中英

MVC reading controller data in View

public ActionResult GetKey()
        {
            CacheKey ck = new CacheKey();
            List<string> value = new List<string>();
            value = CacheManager.Instance.GetAllKeys("");
            return View(value);
        }

Is there any way to read this value on a button click on View. As soon as I click on a button this value should be displayed on a text field or text area.

You can handle button click and create a GET request in JavaScript:

<!-- The button -->
<button onclick="load()">Load</button>

<!-- The text area -->
<span id="result"></span>

The script:

$.get(
  "/ControllerName/GetKey",
  function(result) {
    document.querySelector("#result").textContent = result;
  }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM