我有一个特定的控制器操作没有显示视图的问题.
这是控制器动作:
public ActionResult DisplayStudents(string id)
{
var name = (from p in data.StudentTable.Where(a => a.ClassNumberID == id)
group n by n.StudentName into g
select g.Key).First();
return View(name);
}
Run Code Online (Sandbox Code Playgroud)
控制器名称为"学生",视图显示在"Views/Student/DisplayStudents.aspx"中
为什么我仍然会收到此错误:
Server Error in '/' Application.
--------------------------------------------------------------------------------
The view 'Thomas Guenn' or its master was not found. The following locations were searched:
~/Views/Student/Thomas Guenn.aspx
~/Views/Student/Thomas Guenn.ascx
~/Views/Shared/Thomas Guenn.aspx
~/Views/Shared/Thomas Guenn.ascx
Run Code Online (Sandbox Code Playgroud)
另外,为什么要寻找"Thomas Guenn.aspx"而不是"DisplayStudents.aspx"?
这是我的查看页面:
>"%>DisplayStudents学生如下:
Run Code Online (Sandbox Code Playgroud)<table> <% foreach (var item in Model) { %> <tr> <td> <%= Html.Encode(item)%> </td> </tr> …
我怎样才能按降序排列学生?这是我的代码.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Student.Models;
namespace Student.Controllers {
public class StudentController : Controller
{
//
// GET: /Student/
private IStudentRepository _repository;
public StudentController() : this(new StudentRepository())
{
}
public StudentController(IStudentRepository repository)
{
_repository = repository;
}
public ActionResult Index()
{
return View(_repository.ListAll());
}
}
Run Code Online (Sandbox Code Playgroud) 插入学生后如何在同一浏览器上显示消息?目前我正在使用返回内容将我导航到新页面,但我想在同一页面上显示消息并停留在同一页面上:
索引控制器:
public ActionResult Index()
{
return View(_repository.ListAll().OrderByDescending(s => s.StudentID));
}
Run Code Online (Sandbox Code Playgroud)
控制器动作:
public ActionResult RemoveStudent(int id)
{
StudentDataContext student= new StudentDataContext();
var std = student.Students.Single(s => s.StudentID == id);
student.Students.DeleteOnSubmit(std);
student.SubmitChanges();
return Content("Student " + std.StudentId.ToString() + " Removed");
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我正在尝试使用JavaScript填充HTML选择列表.我相信我做得对,但我无法填写清单.该列表仍然是空的.我在这里错过了什么?
HTML:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<script type="text/javascript" src="../../Scripts/app/Base.js"></script>
<title>Index</title>
</head>
<body>
<div>
Select <select id = "MyList"></select>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS:
window.onload = function(){
var select = document.getElementById("MyList");
var options = ["1", "2", "3", "4", "5"];
for (var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个具有相同ObjectId的对象列表,我想返回一个具有最新DateOrdered的对象.这是一个很好的方法吗?
var LatestObject = (from o in Context.Objects
where p.ObjectId == ObjectId
select p.DateOrdered)
.ToList()
.Max();
Run Code Online (Sandbox Code Playgroud) 如何使用实体框架在一个事务中将数据保存到多个表中?
我有多个用于填充上下文的 void 方法,但我想将其保存在一个事务中,而不是多次保存。这样做的最佳方法是什么?
namespace DataAccess.Services
{
public class Submissions
{
DataContext Context;
public Submissions()
{
Context = new DataContext();
}
public void InsertAllData()
{
//Save all data at once for all below contexts
//DataContext.SaveChanges();
}
void InsertObject1(int Object1Id )
{
var obj1 = new DataAccess.Entity.Object1();
obj1.Field1 = ....
obj1.Field2 = ....
.....
DataContext.Objects.Add(obj1);
}
void InsertObject2(int Object2Id )
{
var obj2 = new DataAccess.Entity.Object2();
obj2.Field1 = ....
obj2.Field2 = ....
.....
DataContext.Objects.Add(obj2);
}
void InsertObject3(int Object3Id )
{
var …Run Code Online (Sandbox Code Playgroud) 我的案例陈述有什么问题?
如果值是数字,那么我想检查它是否大于或等于5并返回1如果是,否则返回0.有没有任何优雅的方法这样做?
CASE下面嵌套在另一个案例中
CASE
WHEN(
xyz <> a
AND abc <> 3
AND
CASE
WHEN ISNUMERIC(LEFT(o.RepCode, 1)) = 1 THEN
CASE
WHEN CONVERT(INT, LEFT(o.RepCode, 1)) >= 5 THEN 1
ELSE 0
END
ELSE 0
END
)
THEN 1
ELSE 0
Run Code Online (Sandbox Code Playgroud)
在WHEN ISNUMERIC()之前的第二个AND之后,我在第一个CASE上得到以下错误
An expression of non-boolean type specified in a context where a condition is expected.
Run Code Online (Sandbox Code Playgroud) 我正在阅读关于MVC的教程 - Linq to SQL.在这里,我注意到他们在对象名称(对象名称中的第一个字符)中使用下划线,例如"_dataContext"
这是代码:
using System.Collections.Generic;
using System.Linq;
namespace MvcApplication1.Models
{
public class MovieRepository : IMovieRepository
{
private MovieDataContext _dataContext;
public MovieRepository()
{
_dataContext = new MovieDataContext();
}
#region IMovieRepository Members
public IList<Movie> ListAll()
{
var movies = from m in _dataContext.Movies
select m;
return movies.ToList();
}
#endregion
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,使用这个下划线的目的是什么?
我有一张受锁定牢房保护的床单.即使在保护工作表的同时检查"排序"和"自动过滤"选项之后,我仍然无法对数据进行排序/过滤.
单击"排序"按钮时,我收到以下消息:
您尝试更改的单元格或图表受到保护,因此是只读的.要修改受保护的单元格或图表,请先删除保护...
我错过了什么吗?
提前致谢
如何使用聚合运算符转换linq查询输出并将不同的输出显示到列表?
这是我存储在DB中的内容,它是通过linq查询提取的:
Date Hours
07/29/2013 1.3
07/29/2013 2.0
07/30/2013 3.1
07/31/2013 0.1
07/31/2013 5.2
08/01/2013 1.1
08/01/2013 1.1
08/01/2013 2.2
08/02/2013 3.3
08/02/2013 4.0
08/03/2013 2.1
Run Code Online (Sandbox Code Playgroud)
这是我想要的数据:
Day Hours
07/29/2013 3.3
07/30/2013 3.1
07/31/2013 5.3
08/01/2013 4.4
08/02/2013 7.3
08/03/2013 2.1
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢
c# ×7
asp.net-mvc ×4
html ×2
linq-to-sql ×2
asp.net ×1
excel ×1
excel-vba ×1
javascript ×1
linq ×1
sql ×1
sql-server ×1
vba ×1