我正在寻找一种方法将ViewDataDictionary传递给ASP.NET MVC中的部分视图,我来到这个语法:
new ViewDataDictionary { { "Name", "Value" } }
Run Code Online (Sandbox Code Playgroud)
我对这里的初始化语法有点困惑.任何人都可以向我解释一下吗?
将我的实体框架更新到版本6.0.0-alpha1后,我无法更新数据库.这是我得到的错误:
PM> update-database -verbose
Using StartUp project 'DataCenter'.
Using NuGet project 'DataCenter.Domain'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'datacenter' (DataSource: ., Provider: System.Data.SqlClient, Origin: Configuration).
Upgrading history table.
ALTER TABLE [dbo].[__MigrationHistory] ADD [ContextKey] [nvarchar](512) NOT NULL DEFAULT 'DataCenter.Domain.Migrations.Configuration'
ALTER TABLE [dbo].[__MigrationHistory] DROP CONSTRAINT [PK_dbo.__MigrationHistory]
System.Data.SqlClient.SqlException (0x80131904): 'PK_dbo.__MigrationHistory' is not a constraint.
Could not drop constraint. See previous errors.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, …Run Code Online (Sandbox Code Playgroud) entity-framework code-first ef-migrations entity-framework-6
我在我的mvc项目中使用ELMAH来记录错误.我意识到有时错误没有记录.所以我将这些语句包装在try..catch中并调用,ErrorSignal.FromCurrentContext().Raise(ex);但没有为该特定错误再次记录.所以我试着进入ELMAH源代码(使用Reflector VS addin).我在elmah看到了这个例外:
A potentially dangerous Request.Form value was detected from the client (Text="<br>").
StackTrace: at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
Run Code Online (Sandbox Code Playgroud)
实际源代码:this._form = CopyCollection(request.Form);in public Error(System.Exception e, HttpContext context)in Error.cs.和CopyCollection方法:
private static NameValueCollection CopyCollection(NameValueCollection collection)
{
if ((collection != null) && (collection.Count != 0))
{
return new NameValueCollection(collection);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
因此.Net不允许从危险的表单数据创建新的NameValueCollection .我的应用程序中有很多Html编辑器,我希望ELMAH能够在任何情况下记录错误.
我能做什么?
我在我的项目中使用了Dapper.我有一个SqlParameters列表,我想将它发送给Dapper.但是Dapper需要一个对象(名称,值).如何将SqlParameter转换为对象.我知道这不起作用:
conn.Query<TModel>(sql, parameters.Select(p => new {p.ParameterName=p.Value}))
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我有一个带有分组的 sql select 命令,我想获取总行数。我该如何实现这一目标?
我的sql命令:
select p.UserName, p.FirstName + ' ' + p.LastName as [FullName]
,count(b.billid) as [Count], sum(b.PercentRials) as [Sum] from Bills b
inner join UserProfiles p on b.PayerUserName=p.UserName
where b.Successful=1
group by p.UserName, p.FirstName + ' ' + p.LastName
Run Code Online (Sandbox Code Playgroud)
我尝试过这些但没有运气:
select count(*) from (select ...)
Run Code Online (Sandbox Code Playgroud)
和
select count(select ...)
Run Code Online (Sandbox Code Playgroud)
编辑
这是我想要运行的完整 sql 语句:
select count(*) from ( select p.UserName, p.FirstName + ' ' + p.LastName as [FullName]
,count(b.billid) as [Count], sum(b.PercentRials) as [Sum] from Bills b
inner join …Run Code Online (Sandbox Code Playgroud) 我知道它之前已被问过,但没有一个对我有效,而我的有点不同.
我的MVC 4项目在本地工作但在服务器中无法运行此错误:
Compiler Error Message: CS0246: The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 194: }
Line 195:
Line 196: protected ProfileCommon Profile {
Line 197: get {
Line 198: return ((ProfileCommon)(this.Context.Profile));
Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e3c4a897\ff4f4317\App_Web_pageheader.ascx.cdcab7d2.rpk2croq.0.cs Line: 196
Run Code Online (Sandbox Code Playgroud)
我编写了一个自定义项ProfileProvider并配置了项目以使用它:
<profile enabled="true" defaultProvider="sql">
<providers>
<clear />
<add name="sql" type="BusinessLogic.ProfileProvider" connectionStringName="c" applicationName="/" />
</providers>
</profile>
Run Code Online (Sandbox Code Playgroud)
我使用ProfileBaseclass来访问用户配置文件ProfileCommon.上面的错误是在编译器生成的文件中.为什么asp.net生成一个无法编译的代码?为什么它在本地工作?
我在本地安装了.Net Framework 4.5.1,但在服务器中它是4.5.它与问题有关吗?
在我的应用程序中,我需要检查Windows版本.我使用的版本辅助功能在Visual Studio 2013 (v120) platform toolset.但是该程序在Windows XP中不起作用.错误是:
'xxx.exe' is not a valid win32 application
Run Code Online (Sandbox Code Playgroud)
所以我将平台工具集更改为Visual Studio 2013 - Windows XP (v120_xp).但在这种情况下,应用程序将无法编译.错误是:
error C1083: Cannot open include file: 'VersionHelpers.h': No such file or directory
Run Code Online (Sandbox Code Playgroud)
我能做什么?我可以使用旧的GetVersionEx功能吗?MSDN说:
GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper APIs
Run Code Online (Sandbox Code Playgroud)
但也许我现在应该用它!
在Kendo Grid中,如果未分配manager,我想显示指向用户的链接,否则显示已分配的manager的名称.因为管理器可以为null,所以我成功地将此链接仅显示在经理不为空时.但问题是如果manager不是null如何在else部分中显示管理器名称
下面是我正在尝试使用的客户端模板:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.AccountManager).Title("Account Manager")
.ClientTemplate("# if (AccountManager == null) { #" + @Html.ActionLink("Assign", "action", "Controller", new { @caseId = "#=CaseID#", @tabIndex = "0" }, new { @Title = "View"}).ToHtmlString() + "# }else {#" + "how to dispaly value of account manager here" + "#} #").HtmlAttributes(new {@style = "text-align:center" });
})
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×2
.net ×1
asp.net ×1
c#-3.0 ×1
c++ ×1
code-first ×1
count ×1
dapper ×1
elmah ×1
kendo-grid ×1
kendo-ui ×1
profile ×1
sql ×1
sql-server ×1
subquery ×1
visual-c++ ×1
windows-xp ×1