我从一个填充我的TempData FormCollection
然后我尝试TempData
用MVC 4 检查我的视图中的值,但我的if
声明没有按照我的预期工作.这是我的代码.
控制器:
[HttpPost]
public ActionResult TestForm(FormCollection data)
{
TempData["username"] = data["var"].ToString(); //data["var"] == "abcd"
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
视图:
@if (TempData["var"] == "abcd")
{
<span>Check</span> //Never displayed
}
else
{
@TempData["var"]; // Display "abcd"
}
Run Code Online (Sandbox Code Playgroud)
这看起来很简单,我不明白为什么我不能显示这个Check
.你能帮助我吗 ?
我有一个拥有许多角色的用户.用户使用链接实体表链接到角色.我已将配置文件设置为在删除用户时级联删除用户角色链接实体.
我们目前正在使用软删除来删除实体.我们添加了一个由删除触发的软删除事件监听器.删除实体时,会触发DeleteEntity
将实体标记为已删除的事件.
我们还有一个覆盖OnPostUpdate
事件,通过在实体上调用Evict来从缓存中删除实体.
如果我创建一个没有任何角色的用户,那么删除它,一切正常(如果级联禁用,它也可以工作).但是,如果我有一个至少分配了一个角色的用户并且我删除了用户,则在调用Evict后OnPostUpdate
,我得到一个NHibernate异常"NHibernate.AssertionFailure:可能的非线程安全访问会话".
我已尝试OnPostUpdate
使用子会话来驱逐实体,但不会抛出异常,但实体不会被驱逐.
public void UserDelete(.....)
{
var user = repository.Fetch<User>(id);
repository.Remove(user);
repository.Connection.Commit();
}
// soft delete event listener
protected override void DeleteEntity(NHibernate.Event.IEventSource session, object entity, ..)
{
var repositoryEntity = entity as deletableentity;
if (repositoryEntity != null)
{
if (!repositoryEntity.IsDeleted)
{
// this marks the entity as deleted
repositoryEntity.isDeleted = true;
// cascade delete
this.CascadeBeforeDelete(session, persister, repositoryEntity, entityEntry, transientEntities);
this.CascadeAfterDelete(session, persister, repositoryEntity, transientEntities);
}
}
}
public void OnPostUpdate(PostUpdateEvent …
Run Code Online (Sandbox Code Playgroud) 我希望能够做的是能够在Visual Studio数据库项目中创建一个定义变量的publising xml脚本,该脚本将用于编写脚本.
我的问题是我得到一个错误:"SQL72008:未定义变量DeployType." 如果我没有在后部署脚本中定义变量,就像这样":setvar DeployType"varchar(100)"
当我运行publish.xml时,DeployType参数正确地设置在生成的脚本的顶部但是该值被":setvar DeployType"varchar(100)覆盖.所以为了使这项工作,我需要手动删除运行此脚本之前的行.
所以问题是如何在没有在postdeployment脚本中默认setvar变量的情况下让项目构建并能够发布?
这是我的PostDeployment.sql文件的内容,它不会在没有默认DeployType变量的情况下构建
--The line causing my problems. I would like to skip it somehow.
:setvar DeployType "varchar(100)"
Print 'Always include core'
:r ..\Data\Core\_BaseCore.sql
--Conditionaly add based on DeployType comming from the publishing.xml
IF ('$(DeployType)' = 'A')
BEGIN
:r ..\Data\A\_BaseKnap.sql
END
ELSE IF ('$(DeployType)' = 'B')
BEGIN
:r ..\Data\B\_BaseB.sql
END
Run Code Online (Sandbox Code Playgroud)
这是Database.publish.xml文件中的内容
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>db name</TargetDatabaseName>
<DeployScriptFileName>Database.sql</DeployScriptFileName>
<ProfileVersionNumber>1</ProfileVersionNumber>
<TargetConnectionString>Connection string</TargetConnectionString>
</PropertyGroup>
<ItemGroup> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试specFlow辅助,不知道如何从表创建类属性.想象一下,我有这堂课:
public class Tracking
{
public string Category { get; set; }
}
public class ODARequest
{
public string Title { get; set; }
public string Name { get; set; }
public Tracking Tracking { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的给定场景是下一个:
Scenario: Successfully create an account
Given I have entered the following data into the ODA form:
| Field | Value |
| Title | Mr |
| Name | Andy |
| Tracking Category | MDA |
public void GivenIHaveEnteredTheFollowingDataIntoTheODAForm(Table …
Run Code Online (Sandbox Code Playgroud) 我知道可以通过右键单击测试项目并选择"实时单元测试"上下文菜单,从实时单元测试中排除整个测试项目.
但在我的解决方案中,我有一些长时间运行/资源密集型测试,我想排除.可以排除个别测试吗?
asp.net-mvc ×1
if-statement ×1
msbuild ×1
nhibernate ×1
specflow ×1
sql ×1
sqlcmd ×1
tempdata ×1
view ×1