razor语法 mvc中前台js中获取ViewData的值

界面js部分:

@using Newtonsoft.Json;
var vData=@Html.Raw(JsonConvert.SerializeObject(ViewData));
var loginId=vData["loginId"];
var headUrl=vData["headUrl"];
var userName=vData["userName"];

如果直接在页面上显示

"user-name" type="text" placeholder="2-15个字符"  value="@ViewData["userName"]"/>

controller部分:

 public IActionResult ProfileEdit(long loginId, string headUrl, string userName)
  {
            ViewData["loginId"] = loginId;
            ViewData["headUrl"] = headUrl;
            ViewData["userName"] =userName;
            return View();
  }

你可能感兴趣的:(前端)