为了账号安全,请及时绑定邮箱和手机立即绑定

我的视图没有看到视图模型并给出错误

我的视图没有看到视图模型并给出错误

C#
撒科打诨 2021-06-01 09:54:33
我的视图没有看到视图模型并给出一个表达式树可能不包含动态操作。当我查找此错误时,大多数人没有在视图上使用 @model xxx。但我用过这是我的用户控制器页面 public class UserController : Controller    {        private readonly DbManager _context;        public UserController(DbManager context)        {            _context = context;        }        [HttpGet]        public IActionResult Kayit()        {            UserViewModel vm = new UserViewModel();            return View(vm);        }        [HttpPost]        public async Task<IActionResult> KayitAsync([Bind("Isim,Soyad,DogumTarihi,KullaniciAdi,Sifre")]Kullanici k)        {            if (ModelState.IsValid)            {                _context.Kullanicilar.Add(k);                await _context.SaveChangesAsync();                return View("thanks");            }            return View("Index");        }    }这是我的用户/Kayit 视图@Model ArtSite.ViewModels.UserViewModel<h2>Kayıt Sayfası</h2><div class="row">    <div class="col-md-4">        <form asp-controller="User" asp-action="Kayit" method="post">            <div asp-validation-summary="All"></div>            <div>                <label asp-for="Isim"></label>                <input asp-for="Isim" />                <span asp-validation-for="Isim"></span>            </div>            <div>                <label asp-for="Soyad"></label>                <input asp-for="Soyad" />                <span asp-validation-for="Soyad"></span>            </div>            <div>                <label asp-for="DogumTarihi"></label>                <input type="date" asp-for="DogumTarihi" />                <span asp-validation-for="DogumTarihi"></span>            </div>            <div>                <label asp-for="KullaniciAdi"></label>                <input asp-for="KullaniciAdi" />                <span asp-validation-for="KullaniciAdi"></span>            </div>         所以请帮助我理解它。
查看完整描述

1 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

你混淆了@Model属性和@model指令,因为它们都是不同的东西,也有不同的目的。您需要 put@model来定义模型以供查看。

@model ArtSite.ViewModels.UserViewModel

另请参阅这篇文章(mvc 大写模型与小写模型)以更详细地了解这些。


查看完整回答
反对 回复 2021-06-05
  • 1 回答
  • 0 关注
  • 112 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信