在where子句中获取orderby的此错误.我之所以这样做,是因为之前,如果我没有定义'人',我会在返回时收到错误,因为人们说这个名字'人'在当前的情境中并不存在.我该如何解决?
public JsonResult PersonsList(string birthyear)
{
TutorialDBContext db = new TutorialDBContext();
var NumericYear = Convert.ToInt32(birthyear);
IQueryable people;
if (birthyear == "All")
{
people = from m in db.persons
select m;
people = people.OrderByDescending(s => s.birthdate);
}
else
{
people = from m in db.persons
where m.birthdate.Year >= NumericYear
where m.birthdate.Year <= (NumericYear + 9)
select m;
}
return Json(people, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud) 我必须在此前言,我对视图模型很新.话虽这么说,我希望有一个带付款和订阅信息的创建视图,比如付款注册页面.我想在我的EF模型中更新多个实体,并且我计划通过viewmodel进行更新.问题是当我尝试根据我的控制器动作创建视图时..我收到此错误:

我的视图模型使用独立的类来GET/POST数据到我的看法......也许我会对此错误的方式.. 它必须有一个主键?它是否需要在我的数据库中并添加为EF实体?我该如何解决?谢谢
这是viewmodel代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MVCProject.DataAccess;
using System.ComponentModel.DataAnnotations;
namespace MVCProject.Models.ViewModel
{
public class PaymentSetupViewModel
{
//Subscription.cs
[Required(ErrorMessage = "required")]
public string Frequency { get; set; }
public DateTime Date { get; set; }
//PaymentMethod.cs
[Required(ErrorMessage = "required")]
[CreditCard]
[Display(Name = "Card Number")]
public string CCNumber { get; set; }
[Required(ErrorMessage = "required")]
[Display(Name = "Card Expiration")]
public DateTime CCExpiration { get; set; }
[Required(ErrorMessage = "required")]
[Display(Name = "CVV2")] …Run Code Online (Sandbox Code Playgroud) 我想为mvc页面制作一个这样的模型:
public class Body
{
public int Id { get; set; }
public class Hand
{
public List<Fingers> fingers { get; set; }
}
public class Foot
{
public List<Toes> toes { get; set; }
}
public class Head
{
public Nose nose {get; set;}
public List<Ears> ears { get; set; }
public List<Eyes> eyes { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个像这样的手指类:
public class Fingers
{
public int Id { get; set; }
public string Description { get; set; } …Run Code Online (Sandbox Code Playgroud) 我对一个视图有两次局部。Partial 不使用循环并具有基本验证。
这是部分视图代码:
<div class="col-md-4">
@Html.LabelFor(model => model.ZipCode, new { @class = "control-label " })
@Html.TextBoxFor(model => model.ZipCode, new { @class = "form-control ", tabindex = "4" })
@Html.ValidationMessageFor(model => model.ZipCode)
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的主要观点,调用它两次:
<div id="homeaddress">
@if (Model == null)
{
@Html.Partial("~/Views/AddrPartial.cshtml", new Address())
}
else
{
@Html.Partial("~/Views/AddrPartial.cshtml", Model.HomeAddress)
}
</div>
<div id="mailingaddress">
@if (Model == null)
{
@Html.Partial("~/Views/AddrPartial.cshtml", new Address())
}
else
{
@Html.Partial("~/Views/AddrPartial.cshtml", Model.MailingAddress)
}
</div>
Run Code Online (Sandbox Code Playgroud)
然后只有“homeadrress”div 验证有效...这是我的模型的设置方式:
public class Information
{
public Address HomeAddress …Run Code Online (Sandbox Code Playgroud) 这是我的代码.我基本上想看看我的模型,看看是否存在任何东西.使用三元运算符根据存在显示或隐藏.
$(document).ready(function() {
(@Model.MyProperties.Any()) ? $('#removeall-toggle').show() : $('#removeall-toggle').hide();
});
Run Code Online (Sandbox Code Playgroud)
我在chrome dev工具中遇到错误,说:
Uncaught ReferenceError: False is not defined
Run Code Online (Sandbox Code Playgroud)
我如何解决这个问题,或者这是一个更好的方法来实现这一目标?
asp.net-mvc ×4
c# ×4
razor ×3
.net ×2
iqueryable ×1
javascript ×1
jquery ×1
linq ×1
regex ×1
viewmodel ×1