是否有可能有一个编辑多个记录的视图,就像index.cshtml视图循环通过记录显示它们一样(如下所示)?
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.tvid)
</td>
Run Code Online (Sandbox Code Playgroud)
因此,对于上面的每一行,它将与数据库中的不同行相关.
有谁知道有任何例子说明如何实现这一目标?
谢谢你的任何指示,
标记
UPDATE
模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcObjectives.Models
{
public class objectives
{
public int ID { get; set; }
public int tvid { get; set; }
public string tlnt { get; set; }
public DateTime month { get; set; }
public string objective { get; set; }
public int score { get; set; }
public int possscore { …Run Code Online (Sandbox Code Playgroud) 我正在使用现有的数据库,希望更新到asp.net MVC 4.我很难为两个表创建模型.Rule和RuleApply表.
我希望使用类似的东西来查询它:
var rules = db.Rules.Include("RulesApply").Where(t => t.rule_active == 1).ToList();
Run Code Online (Sandbox Code Playgroud)
RuleApply表没有主键(它只是用作查找表) - 所以当我尝试编译时,我收到错误:
EntityType"RuleApply"没有定义键.定义此EntityType的键.
有什么办法可以将Rule.id与RuleApply.rule_id链接起来吗?或者现有的表,必须添加一个主键,以允许我使用EF/Linq等?
namespace emc.Models
{
public class Rule
{
[Key]
public int id { get; set; }
public int type_id { get; set; }
public int rule_active { get; set; }
public DateTime rule_start { get; set; }
public DateTime rule_end { get; set; }
public virtual ICollection<RuleApply> RulesApply { get; set; }
}
public class RuleApply
{
public int type_id { get; set; } …Run Code Online (Sandbox Code Playgroud) 我知道在Visual Studio中有一个扩展.但是,是否有人知道Visual Studio Express版本的类似扩展或设置?
可以让我崩溃的东西:
if (!string.IsNullOrEmpty(hotel.bg3))
{
colspan += 1;
TableCell c3 = new TableCell();
c3.Text = hotel.bg3.Replace(" ", "<br />");
c3.Style.Value = "border-color: #333333; border-width: 1pt; border-style: none none solid none; font-weight:bold;";
c3.HorizontalAlign = HorizontalAlign.Center;
row.Controls.Add(c3);
}
Run Code Online (Sandbox Code Playgroud)
至:
if (!string.IsNullOrEmpty(hotel.bg3))
{...}
Run Code Online (Sandbox Code Playgroud)
谢谢,
标记
我正在尝试使用KnockOutJS和jQuery - 有什么方法可以检查下面的allData,看看它是否返回了什么?
如果没有,我想在屏幕上隐藏div:
$(document).ready(function () {
$("#thankyou").hide(); // hide thank you box
$("#searchBtn").click(function () {
$.getJSON("/api/searchapi/", function (allData) {
sampleProductCategories = allData; // I want to check if this has returned anything?
if(!allData) { alert("nothing");}
cart.RoomCategories(sampleProductCategories);
});
});
});
Run Code Online (Sandbox Code Playgroud)
Firebug将空JSON显示为:

我有一个简单的Linq查询,它按一个字段分组Team:
var qbt = db.Calls.GroupBy(x => x.team).Select(call => new
{
Team = call.Key,
Number=call.Count()
});
Run Code Online (Sandbox Code Playgroud)
哪个回报:
Team Number
ta 100
tb 98
tc 123
Run Code Online (Sandbox Code Playgroud)
如何将查询更改为具有附加列"status",以便它返回:
Team Number Status
ta 40 Open
ta 60 Closed
tb 58 Open
tb 40 Closed
tc 1 Open
tc 122 Closed
Run Code Online (Sandbox Code Playgroud)
我尝试添加另一组:
var qbt = db.Calls.GroupBy(x => x.team).GroupBy(y => y.status).Select(call => new
{
Team = call.Key,
Status = call.Key2,
Number=call.Count()
});
Run Code Online (Sandbox Code Playgroud)
......但那不会编译.
谢谢,马克
我有一个Topic父表,一个Post表childed到Topic表.
我在Linq查询中尝试做的是从链接的Post表返回最后一个发布日期,但是,如果没有Posts,则下面的查询失败,因为DateTime不可为空:
The cast to value type 'DateTime' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
查询是:
var topic = db.Topics.Include(x => x.Posts).Include(x => x.Forum).Where(x => x.ForumId==id)
.Select(t => new TopicViewModel
{
TopicId =t.TopicId,
ForumId=t.ForumId,
Title=t.Title,
DateOfTopic=t.DateOfPost,
Replies=t.Posts.Count()-1,
Author=t.Author,
Views = t.Views,
LastPost = t.Posts.OrderByDescending(x => x.DateOfPost).FirstOrDefault().Author,
LastPostDate = t.Posts.OrderByDescending(x => x.DateOfPost).FirstOrDefault().DateOfPost
}).OrderByDescending(x=> x.DateOfTopic).ToList();
Run Code Online (Sandbox Code Playgroud)
我的ViewModel是:
public class TopicViewModel
{
public int TopicId { get; set; }
[Required] …Run Code Online (Sandbox Code Playgroud) 我在这里有一个小提琴:http://jsfiddle.net/94wQJ/1/ - 但也许有人可以通过下面看看建议.
<button type="button" id="allocate">Calc</button>
$('#allocate').click(function () {
val1 = 25.00;
val2 = 16.37;
val3 = val1-val2;
alert(val3);
});
Run Code Online (Sandbox Code Playgroud)
25 - 16.37 = 8.63 - 但是,val3的警报= 8.62999999999
为什么不准确?
谢谢,
标记
我有以下代码,它应该返回60的偏移量(显示目前在英国,我们在英国夏令时 - 即比格林威治标准时间早60分钟):
var info = TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
double off = localServerTime.Offset.TotalMinutes;
return off;
Run Code Online (Sandbox Code Playgroud)
但是,它返回0.
有人可以帮我解决这个问题吗?
我试图从文本框中取一个输入,替换其中的一些字符串 - 并将原始和替换字符串返回到视图,并填充两个单独的文本框.
我的简单视图模型是:
public class WordsToConvert
{
public string Original { get; set; }
public string Replacement { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的cshtml文件有一个表单,当Post返回到同一视图时,它与我想要填充的表单相同:
@Html.EditorFor(model => model.Original,
new { htmlAttributes = new { @class = "form-control" } })
@Html.EditorFor(model => model.Replacement,
new { htmlAttributes = new { @class = "form-control" } })
Run Code Online (Sandbox Code Playgroud)
我的控制器非常简单(只是为了开始):
// POST: WTC
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult WTC([Bind(Include = "Original,Replacement")] WordsToConvert wordsToConvert)
{
if (ModelState.IsValid)
{
wordsToConvert.Replacement = "Test " + wordsToConvert.Original;
return View(wordsToConvert); // <---- at …Run Code Online (Sandbox Code Playgroud) 我已经看到了很多答案 - 但似乎无法让它们起作用:
var numinqtoday = bc.SSRecs.Where(x => x.DateTime == id).Select(n => new
{
refer = n.@ref
}).GroupBy(x => x.refer).ToList();
var numinqprev = bc.SSRecs.Where(x => x.DateTime < id).Select(n => new
{
refer = n.@ref
}).GroupBy(x => x.refer).ToList();
var filtered = numinqtoday.Except(numinqprev).ToList();
Run Code Online (Sandbox Code Playgroud)
在我上面的代码中:
numinqtoday.Count() = 184
numinqprev.Count() = 155
filtered.Count() = 184
Run Code Online (Sandbox Code Playgroud)
我已经检查过numinqtoday中numinqprev中肯定会出现 - 所以看起来.Except在放入过滤之前没有删除它们.
有人可以告诉我哪里出错了吗?
谢谢,
标记
c# ×7
asp.net-mvc ×4
linq ×4
linq-to-sql ×3
jquery ×2
.net ×1
ajax ×1
asp.net ×1
dst ×1
javascript ×1
jquery-ui ×1
knockout.js ×1