我有一个编辑应用程序视图,可以在以下URL找到它:
HTTP://本地主机:17262 /应用/ EditApplication/1
1等于应用程序ID.
同样在页面上,我有一个链接转到另一个视图,为应用程序添加助手.我想传递应用程序ID,以便新助手可以"链接"到此应用程序.如何获得值1并将其添加到我的操作链接?到目前为止,这就是我的HTML中的内容:
<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = "id" }, null) %>
Run Code Online (Sandbox Code Playgroud)
有人可以建议吗?
谢谢
我Entity Framework 4.1 code first用来连接已经存在的数据库.我首先使用的表被称为Bank.我也有一个Bank class作为我的域模型.这是我映射我的类和表的方式:
public class HbfContext : DbContext
{
public DbSet<Bank> Banks { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Bank>().ToTable("Bank");
}
}
Run Code Online (Sandbox Code Playgroud)
我的银行表:
BankID INT
BankName VARCHAR(50)
Run Code Online (Sandbox Code Playgroud)
My Bank类看起来像这样:
public class Bank
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我想要归还所有银行时,我遇到了问题.从以下位置返回的SQL语句:
return db.Banks
.OrderBy(x => x.Name);
Run Code Online (Sandbox Code Playgroud)
是:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS …Run Code Online (Sandbox Code Playgroud) 我使用的是最新版本log4net.关于connectionType版本和公钥值的几个问题.
您在log4net网站上获得的示例如下所示:
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Run Code Online (Sandbox Code Playgroud)
我在SO上看到了以下内容:
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Run Code Online (Sandbox Code Playgroud)
我正在使用Visual Studio 2012和SQL Server 2008 R2.我怎么知道我需要使用什么版本以及公钥是什么(两个版本似乎都相同)?
在单个视图中的两个查询之间进行迭代.
在我的应用程序中,有一个特定产品的比较列表.在页面顶部,有该产品的详细信息,如名称,最低/最高价格,照片和其他一些细节.
我需要的是这样的:
@modelComparisonList List<MyApp.Models.Products>
@modelProduct MyApp.Models.Products
@{
ViewBag.Title = "Comparing " + modelProduct.name;
}
<h1>There is @modelProduct.quantity products to compare</h1>
<table>
@foreach (var item in modelComparisonList)
{
<tr>
<p>@item.productName</p>
</tr>
<tr>
<p>@item.productPrice</p>
</tr>
<tr>
<p>@item.marketName</p>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
你能理解我的情况吗?
我不知道如何执行解决方案来解决这个问题.有人可以给我一个想法吗?
我使用ASP.NET MVC 5与bundling and minification和得到一个奇怪的错误,当我在调试设置为false web.config.
我一直在使用捆绑和缩小一段时间,并且昨晚只是第一次看到这个错误因为我的下拉菜单不起作用.我无法确认这是否有效,因为我从未检查过文件.
这是部分错误:
/* Minification failed. Returning unminified contents.
(2,1): run-time error CSS1019: Unexpected token, found '!'
(2,2): run-time error CSS1019: Unexpected token, found 'function('
(2,14): run-time error CSS1031: Expected selector, found ')'
(2,14): run-time error CSS1025: Expected comma or open brace, found ')'
(2,212): run-time error CSS1019: Unexpected token, found '('
(2,213): run-time error CSS1019: Unexpected token, found '"undefined"'
(2,224): run-time error CSS1019: Unexpected token, found '!'
(2,225): run-time …Run Code Online (Sandbox Code Playgroud) 我正在使用.NET 4,NUnit和Rhino模拟.我想对我的新闻库进行单元测试,但我不确定如何去做.我的新闻存储库是我最终将用于与数据库通信的内容.我想用它来测试假/伪数据.不确定是否可能?这就是我目前拥有的:
public interface INewsRepository
{
IEnumerable<News> FindAll();
}
public class NewsRepository : INewsRepository
{
private readonly INewsRepository newsRepository;
public NewsRepository(INewsRepository newsRepository)
{
this.newsRepository = newsRepository;
}
public IEnumerable<News> FindAll()
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我的单元测试看起来像这样:
public class NewsRepositoryTest
{
private INewsRepository newsRepository;
[SetUp]
public void Init()
{
newsRepository = MockRepository.GenerateMock<NewsRepository>();
}
[Test]
public void FindAll_should_return_correct_news()
{
// Arrange
List<News> newsList = new List<News>();
newsList.Add(new News { Id = 1, Title = "Test Title 1" });
newsList.Add(new News { Id …Run Code Online (Sandbox Code Playgroud) 我使用ASP.NET MVC 3与Razor和Autofac依赖注入.
我正在考虑创建一个通用映射器.目前我AutoMapper用于我的域和视图模型之间的映射.它可以是任何映射框架,但我使用的是AutoMapper.
这是我的IMapper界面:
public interface IMapper
{
object Map(object source, Type sourceType, Type destinationType);
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个实现这个IMapper接口的IBankMapper接口.我这样做的原因是因为我可以有很多不同的映射器.使用依赖注入我可以知道我可以注入什么实例.所以对于IBankMapper我会注入BankMapper,ICategoryMapper我会注入CategoryMapper.
IBankMapper 接口:
public interface IBankMapper : IMapper
{
}
Run Code Online (Sandbox Code Playgroud)
BankMapper 类:
public class BankMapper : IBankMapper
{
static BankMapper()
{
Mapper.CreateMap<Bank, EditBankViewModel>();
Mapper.CreateMap<EditBankViewModel, Bank>();
}
public object Map(object source, Type sourceType, Type destinationType)
{
return Mapper.Map(source, sourceType, destinationType);
}
}
Run Code Online (Sandbox Code Playgroud)
随着程序的增长,映射器类也将如此.有没有办法可以创建一个通用映射器,可以在整个应用程序中使用?这可能吗?
我在用Entity Framework 5 code first.我试图在2个表之间设置内部联接,我不知道如何去做.这两个表没有主键/外键关联,但它们具有公共字段域.
tblServer表:
Server_ID
ServerName
Domain
...
...
Run Code Online (Sandbox Code Playgroud)
tblCommandExecutionServer表:
ServerListID
ServerName
Domain
...
...
Run Code Online (Sandbox Code Playgroud)
这就是我如何配置2个表来映射到某些实体类:
ServerConfiguration类:
class ServerConfiguration : EntityTypeConfiguration<Server>
{
internal ServerConfiguration()
{
this.ToTable("tblServer");
this.Property(x => x.Id).HasColumnName("Server_ID");
this.Property(x => x.Name).HasColumnName("ServerName");
}
}
Run Code Online (Sandbox Code Playgroud)
CommandExecutionServerConfiguration类:
class CommandExecutionServerConfiguration : EntityTypeConfiguration<CommandExecutionServer>
{
internal CommandExecutionServerConfiguration()
{
this.ToTable("tblCommandExecutionServer");
this.Property(x => x.Id).HasColumnName("ServerListID");
this.Property(x => x.Name).HasColumnName("ServerName");
}
}
Run Code Online (Sandbox Code Playgroud)
服务器类:
public class Server : IEntity
{
public int Id { get; set; }
public string Name { get; set; }
public string …Run Code Online (Sandbox Code Playgroud) ado.net entity-framework entity-framework-4 entity-framework-4.1 entity-framework-5
我试图了解 async/await 以查看是否需要在应用ASP.NET MVC 5程序中使用异步调用进行转变。
当我用值填充视图模型时,我有以下内容:
MyViewModel myViewModel = new MyViewModel();
myViewModel.Answer1 = await myService.CalculateAnswer1Async();
myViewModel.Answer2 = await myService.CalculateAnswer2Async();
Run Code Online (Sandbox Code Playgroud)
上述2个方法背后的代码:
public async Task<int> CalculateAnswer1Async()
{
await Task.Delay(5000);
return 111;
}
public async Task<int> CalculateAnswer2Async()
{
await Task.Delay(6000);
return 222;
}
Run Code Online (Sandbox Code Playgroud)
据我了解,上述两种方法将依次执行,先执行CalculateAnswer1Async(),然后执行CalculateAnswer2Async()。那么完成此操作所需的最长时间应该约为 6 秒(CalculateAnswer2Async() 完成所需的时间)?但是当我运行页面时,加载大约需要11秒,即5秒+6秒=11秒。
有人可以帮我澄清一下我做错了什么吗?
我当前的设置Google Analytics如下所示:
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
Run Code Online (Sandbox Code Playgroud)
我阅读了这篇文章,解释了如何在使用超过 1 个跟踪 ID 时跟踪数据:
https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers
因此,使用链接中的示例,我需要添加以下几行脚本:
ga('create', 'UA-XXXXXXXX-2', 'auto', 'myTracker2');
ga('myTracker2.send', 'pageview');
Run Code Online (Sandbox Code Playgroud)
我该怎么办displayfeatures?我也需要预先myTracker2准备吗?就像是:
ga('myTracker2.require', 'displayfeatures');
Run Code Online (Sandbox Code Playgroud) javascript analytics google-analytics google-analytics-api universal-analytics
c# ×7
asp.net ×4
asp.net-mvc ×4
.net ×2
ado.net ×1
analytics ×1
javascript ×1
jquery ×1
log4net ×1
nunit ×1
razor ×1
rhino-mocks ×1
sql-server ×1
unit-testing ×1