我想在我的助手中访问TempData以获取flash消息(比如在ruby中)
我得到一个运行时错误
The name 'TempData' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)
我的Flash.cshtml如下
@helper Show()
{
var message = "test message";
var className = "info";
if (TempData["info"] != null)
{
message = TempData["info"].ToString();
className = "info";
}
else if (TempData["warning"] != null)
{
message = TempData["warning"].ToString();
className = "warning";
}
else if (TempData["error"] != null)
{
message = TempData["error"].ToString();
className = "error";
}
<script>
$(document).ready(function () {
$('#flash').html('@HttpUtility.HtmlEncode(message)');
$('#flash').toggleClass('@className');
$('#flash').slideDown('slow');
$('#flash').click(function () { $('#flash').toggle('highlight') });
});
</script>
} …Run Code Online (Sandbox Code Playgroud) 这是我的nlog.config文件.我已经打开了throwsException.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
<targets>
<target type="Database" name="databaseLog"
dbProvider="sqlserver" connectionstring="server=.\SQLExpress;database=Movie;integrated security=true">
<commandText>
INSERT INTO [Log] ([Description] , [Level] ) VALUES (@Description, @Level )
</commandText>
<parameter name="@Description" layout="${message}"/>
<parameter name="@Level" layout="${level}"/>
</target>
</targets>
<rules>
<logger name="*" minLevel="Trace" appendTo="databaseLog"/>
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
这将工作,并将记录插入数据库.但是我想使用connectionstringName而不是重新键入connectionstring.当我改变的ConnectionString到的connectionStringName这样....
connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"
Run Code Online (Sandbox Code Playgroud)
至
connectionStringName="ApplicationConnectionString"
Run Code Online (Sandbox Code Playgroud)
我得到一个错误期望'providerInvariantName'参数的非空字符串
有没有一个使用msbuild创建数据库的好教程?
jean paul boodhoo在这篇文章中使用了nant .他设置要在nant构建文件中使用的属性
<properties>
<property name="sqlToolsFolder" value="C:\Program Files\Microsoft SQL Server\90\Tools\Binn"/>
<property name="osql.ConnectionString" value="-E"/>
<property name="initial.catalog" value="Northwind"/>
<property name="config.ConnectionString" value="data source=(local);Integrated Security=SSPI;Initial Catalog=${initial.catalog}"/>
<property name="database.path" value="C:\root\development\databases" />
<property name="osql.exe" value="${sqlToolsFolder}\osql.exe" />
</properties>
Run Code Online (Sandbox Code Playgroud)
然后可以使用这样的命令行创建数据库..
c:\> build builddb
Run Code Online (Sandbox Code Playgroud)
我安装了MSBuild扩展包但我找不到输入连接字符串的位置来连接数据库
谢谢
解决
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="constants.proj"/>
<Target Name="QueryDb">
<PropertyGroup>
<_Command>-Q "SELECT * FROM Users"</_Command>
<_Command2>-i test.sql</_Command2>
</PropertyGroup>
<Exec Command="$(sqlcmd) $(_Command)" /><!---->
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
和Constants.proj看起来像这样
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
<initialCatalog>NorthwindTest</initialCatalog>
<serverInstance>(local)\SQLEXPRESS</serverInstance>
<configConnectionString>data source=$(serverInstance);Integrated Security=SSPI;Initial …Run Code Online (Sandbox Code Playgroud) 如何在不先创建列的情况下创建临时表?
CREATE TABLE #Yaks (
YakID int,
YakName char(30) )
select name
from tempdb..sysobjects
where name like '#yak%'
drop table #yaks
Run Code Online (Sandbox Code Playgroud)
首先定义表是一件痛苦的事.
有没有办法将消息的子字符串获取到 nlog 布局?就像是${${substring(0,200)}message}
<parameter name="@Summary" layout="${substring(0,200)}${message}"/>
Run Code Online (Sandbox Code Playgroud)
如果这能写出 message.substring(0, 200); 的等价物,那就太酷了。
<target type="Database" name="databaseLog"
ConnectionStringName="ApplicationConnectionString">
<commandText>
INSERT INTO [Log] ([Description] ,[Summary] ,[Level] )
VALUES (@Description, @Summary, @Level )
</commandText>
<parameter name="@Description" layout="${message}"/>
<parameter name="@Summary" layout="{{SUBSTRING-OF-MESSAGE-HERE}}"/>
<parameter name="@Level" layout="${level}"/>
</target>
Run Code Online (Sandbox Code Playgroud) 以下代码将返回动态对象的 Enumerable。
protected override dynamic Get(int id)
{
Func<dynamic, bool> check = x => x.ID == id;
return Enumerable.Where<dynamic>(this.Get(), check);
}
Run Code Online (Sandbox Code Playgroud)
如何选择FirstOrDefault使其成为单个对象而不是 Enumerable?
与此答案类似,但只想要 SingleOrDefault。
我想有部署一个脚本这是rerunable.所以我在重命名之前检查表是否存在.
IF EXISTS ( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Schema]') AND type IN ( N'U' ) )
BEGIN
sp_rename [Schema], [SchemaInfo]
END
Run Code Online (Sandbox Code Playgroud)
错误是
'sp_rename'附近的语法不正确.
我正在尝试使用JavaScript绘制cos曲线。我希望整个网页都能看到漂亮的cos曲线。像这样...

我加了200以向下移动曲线,这样我就可以看到整个内容。我乘以100,因为html中没有小数位。如果您看一下jsfiddle,那是一团糟
$(function(){
for (i=0; i<500; i++){
var el = $('<div class="dot"></div>');
var y = Math.cos(i*100) * 100 + 200;
var x = i ;
el.css({ 'left' : x+'px' , 'top':y+ 'px'});
$('#main').after(el);
}
});?
Run Code Online (Sandbox Code Playgroud) 我在读Rick Strahls
我希望能够将JObject用于该操作.我写了一个像这样的控制器
public class AlbumsController : Controller
{
[System.Web.Http.HttpPost]
public string PostAlbum(JObject jsonData)
{
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)
前端看起来像这样
当ajax被调用时,我得到一个错误
$("#a").click(function () {
var album = {
AlbumName: "PowerAge",
Entered: "1/1/1977"
}
$.ajax(
{
url: "Albums/PostAlbum",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ Album: album }),
success: function (result) {
alert(result.Result);
}
});
});
Run Code Online (Sandbox Code Playgroud)
POST http://localhost:50066/Albums/PostAlbum 500 (Internal Server Error) jquery-1.7.1.js:8102发送jquery-1.7.1.js:8102 jQuery.extend.ajax jquery-1.7.1.js:7580(匿名函数)专辑:74 jQuery.event.dispatch jquery-1.7.1 .js:3256 elemData.handle.eventHandle
asp.net-mvc ×2
c# ×2
nlog ×2
sql ×2
sql-server ×2
.net-4.0 ×1
dynamic ×1
html-helper ×1
javascript ×1
jquery ×1
json ×1
json.net ×1
lambda ×1
linq ×1
logging ×1
math ×1
msbuild ×1
trigonometry ×1
view-helpers ×1