我想在日历视图中为每一天添加一个简单的复选框功能.它必须与当前日历的样式内联,并且当选择bool时,它必须能够将更改保存到数据库.任何建议,将不胜感激.
我目前的主要问题是正在选择的复选框没有保存到数据库中.
Controller.cs
private F2FW _db = new F2FW();
[HttpGet]
public ActionResult CalendarIndex()
{
List<Event> events = new List<Event>();
Project.Models.Calendar calendar = new Project.Models.Calendar();
calendar.SetDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
calendar.View(@"~\Views\Patient\Calendar.cshtml");
calendar.ViewData.Add("events", events);
ViewBag.calendar = calendar.Render();
return View(calendar);
}
[HttpPost]
public ActionResult CalendarIndex(User user, CalendarArg calArg, int dayCounter, string[] cbx_day, Patient patient, SessionExercise sessionExercise)
{
SessionInformation sessiondata = new SessionInformation();
Session lastsession = db.Sessions.Where(s => s.ActiveUserID == user.UserID).OrderByDescending(e => e.StartedAt).FirstOrDefault();
calArg.CompletedToday = DateTime.Today;
if (ModelState.IsValid)
{
if (calArg.CompletionRequested == false)
{
//do nothing! …Run Code Online (Sandbox Code Playgroud) 作为Multiplesight提供的OdeToFood培训计划的一部分。
错误信息:
EntityFramework.SqlServer.dll中发生类型为'System.NotSupportedException'的异常,但未在用户代码中处理
附加信息:不能在LINQ to Entities查询中构造实体或复杂类型'OdeToFood.Models.RestaurantListViewModel'。
错误来自(_Restaurant.cshtml):
@model IEnumerable<OdeToFood.Models.RestaurantListViewModel>
<div id="restaurantList">
@foreach (var item in Model)
{
<div>
<h4>@item.Name</h4>
<div>
@item.City, @item.Country
</div>
<div>
Reviews: @item.CountOfReviews
</div>
<hr />
</div>
}
</div>
Run Code Online (Sandbox Code Playgroud)
Index.cshtml
@model IEnumerable<OdeToFood.Models.RestaurantListViewModel>
@{
ViewBag.Title = "Home Page";
}
<form method="get" action="@Url.Action("Index")"
data-otf-ajax="true" data-otf-target="#restaurantList">
<input type="search" name="searchTerm" />
<input type="submit" value="Search By Name" />
</form>
@Html.Partial("_Restaurants", Model)
Run Code Online (Sandbox Code Playgroud)
HomeController.cs
using OdeToFood.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Web;
using System.Web.Mvc;
namespace OdeToFood.Controllers
{
public class HomeController …Run Code Online (Sandbox Code Playgroud) 我在尝试从.edmx模型中创建家庭控制器的局部视图时遇到了很多麻烦.
我无法更改此模型的属性,因为它是我正在构建此网站的另一个系统的一部分.
我花了很长时间试图解决这个问题并来到这里希望得到一些帮助和建议.
目标:_Patient.cshtml使用模型中的.edmx模型在主页上渲染局部视图.我希望你能告诉我哪里出错了,因为它不起作用.
问题是什么?
我收到多个错误,例如:
model :: EntityType模型没有定义键.定义此实体类型的键.
传递到字典中的模型项是"模型"类型,但此字典需要类型为"System.Collections.Generic.IEnumerable"的模型项.
使用泛型类型'system.collections.generic.ienumerable需要1个类型参数MVC
目前我收到了这个错误, 但我觉得它位于一长串列表的前面.
传递到字典中的模型项的类型为'FaceToFaceWebsite.Models.PatientListViewModel',但此字典需要类型为'System.Collections.Generic.IEnumerable`1 [FaceToFaceWebsite.Models.PatientListViewModel]'的模型项.
下面是.edmx (因为我无法发布图片..
用户(edmx)-Properties- UserID CodeName UseBriefInstructions Device_DeviceID -Navigation Properties- Device RegimeItems
设备 -Properties- DeviceID名称 - 导航属性 - 用户
Session -Properties- SessionID ActiveUserID ActiveDeviceID StartedAt ReachedFinish -Navigation Properties- SessionExcercises
(Edmx比显示的更大,但是这些是我目前需要使用的模型.但是会话和用户通过另一个模型实际上是链接的)
HomeController.cs
using FaceToFaceWebsite.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.Web;
using System.Web.Mvc;
using PagedList;
using System.Web.UI;
using System.Configuration;
using System.Collections;
namespace FaceToFaceWebsite.Controllers
{
public …Run Code Online (Sandbox Code Playgroud) 我有一个RegimeItemID我在控制器中使用的模型属性.但是,当我试图调用它时,它会给出一个它不存在的错误.我做错了什么?
调节器
public ActionResult ExerciseIndex(int? id, UserExerciseViewModel vmodel)
{
User user = db.Users.Find(id);
//user.RegimeItems = ChosenExercises();
UserExerciseViewModel model = new UserExerciseViewModel { AvailableExercises = GetAllExercises(), RequestedExercises = ChosenExercises(user, vmodel) };
//user.RegimeItems = db.RegimeItems.Find(model.SelectedExercise);
user.RegimeItems = model.RequestedExercises;
return View(model);
}
private List<RegimeItem> ChosenExercises(User user, UserExerciseViewModel model)//RegimeItem regimeItem)//User user, RegimeItem regimeItem)
{
return db.Users.Where(r => r.RegimeItems.RegimeItemID == user.UserID).ToList();
}
Run Code Online (Sandbox Code Playgroud)
楷模
public class User
{
public int UserID { get; set; }
public ICollection<RegimeItem> RegimeItems { get; set; }
public User() …Run Code Online (Sandbox Code Playgroud)