我在以下代码行中一直收到上述错误:
<select
id="buildingSlctRoom@{Model.roomNo;}Request@{Model.RequestNo;}"
class="form-control"
onchange="fillRooms(@{Model.roomNo;},@{Model.RequestNo;},$('#buildingsslctRoom@{Model.roomNo;}Request@{Model.RequestNo;}').val())"
style="width:auto;">
我无法从该代码中看到任何可能导致此问题的内容?
有什么想法吗?
由于
包含roomNo和RequestNo
的类 namespace Timetabling06.ModelViews
{
public class roomCheckerObject
{
public string code { get; set; }
public ICollection<room> rooms { get; set; }
public ICollection<room> deptRooms { get; set; }
public ICollection<building> buildings { get; set; }
public int roomNo { get; set; }
public int RequestNo { get; set; }
}
}
设置对象变量的代码:
public ActionResult _roomChecker(int roomNum, int requestNum, String user, int roundID, int day, int time, int length,int[] weeks,int students,String roomType,String park, String[] facilities){
var rooms = db.rooms.Include(r=>r.building).Include(r=>r.facilities);
rooms = rooms.Where(r => r.capacity >= students);
if(roomType != "Any"){
rooms = rooms.Where(r=>r.roomType.Equals(roomType));
}
if (park != "Any") {
rooms = rooms.Where(r=>r.building.park.Equals(park));
}
if (facilities != null)
{
for (var i = 0; i < facilities.Length; i++)
{
rooms = rooms.Where(r => r.facilities.Any(f => f.facilityName.Equals(facilities[i])));
}
}
var deptRooms = db.rooms.Include(r => r.building).Include(r => r.facilities).Where(r=>r.belongsTo.Equals(user));
roomCheckerObject suitableRooms = new roomCheckerObject();
suitableRooms.code = user;
suitableRooms.roomNo = roomNum;
suitableRooms.RequestNo = requestNum;
if(rooms.Count() >0){
suitableRooms.rooms = rooms.ToList();
var buildings = rooms.Select(r => r.building).Distinct();
suitableRooms.buildings = buildings.ToList();
}
if(deptRooms.Count() >0){
suitableRooms.deptRooms = deptRooms.ToList();
}
return PartialView(suitableRooms);
}
答案 0 :(得分:2)
@{Model.RequestNo;},$('#buildingsslctRoom@{Model.roomNo;}
将此代码更改为此
@Model.RequestNo,$('#buildingsslctRoom@Model.roomNo
remove {} char,这是执行代码,而不是使用值。 Ot应该解决你的问题。
答案 1 :(得分:1)
您正在尝试在html中编写剃刀代码,但您的写作方式不正确。
要在html中编写剃刀代码,您需要这样做:
<select
id="buildingSlctRoom@(Model.roomNo)Request@(Model.RequestNo)"
class="form-control"
onchange="fillRooms('@Model.roomNo','@Model.RequestNo',$('#buildingsslctRoom@(Model.roomNo)Request@(Model.RequestNo)').val())"
style="width:auto;">
答案 2 :(得分:1)
问题是@{Model.roomNo;}
被评估为命令。它会给你你的异常,因为它既不是方法调用也不是属性赋值(如异常所写)。
如果您只想输出值@( Model.roomNo)