我有以下控制器操作:
[HttpPost]
public ViewResult DoSomething(MyModel model)
{
// do something
return View();
}
Run Code Online (Sandbox Code Playgroud)
哪里MyModel是这样的:
public class MyModel
{
public string PropertyA {get; set;}
public IList<int> PropertyB {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
所以DefaultModelBinder应该没有问题地绑定它.唯一的事情是我想使用特殊/自定义绑定器进行绑定PropertyB,我也想重用这个绑定器.所以我认为解决方案是在PropertyB之前放置一个ModelBinder属性,当然这不起作用(属性上不允许使用ModelBinder属性).我看到两个解决方案:
要在每个属性上使用动作参数而不是整个模型(我不喜欢,因为模型具有很多属性),如下所示:
public ViewResult DoSomething(string propertyA, [ModelBinder(typeof(MyModelBinder))] propertyB)
Run Code Online (Sandbox Code Playgroud)要创建一个新类型,可以说MyCustomType: List<int>并注册此类型的模型绑定器(这是一个选项)
也许为MyModel创建一个绑定器,覆盖BindProperty以及该属性是否"PropertyB"使用我的自定义绑定器绑定该属性.这可能吗?
还有其他解决方案吗?
我试图找到使用Silverlight(3)中的MVVM模式从ChildWindow/popup获取数据的正确方法.例如:我有一个带有数据输入表单的主页面,我想打开一个带有客户列表的弹出窗口.当用户选择客户时,我想将所选客户转移到主页面.这就是我目前使用的(示例)代码:
主页
public partial class MainPage : UserControl
{
public MainPageViewModel ViewModel { get; private set; }
public MainPage()
{
InitializeComponent();
ViewModel = new MainPageViewModel();
DataContext = ViewModel;
}
private void SearchCustomer_Click(object sender, RoutedEventArgs e)
{
ViewModel.SearchCustomer();
}
}
public class MainPageViewModel: ViewModel
{
private string customer;
public string Customer
{
get { return customer; }
set { customer = value; RaisePropertyChanged("Customer"); }
}
public void SearchCustomer()
{
// Called from a view
SearchWindow searchWindow = new SearchWindow();
searchWindow.Closed += …Run Code Online (Sandbox Code Playgroud) 我有一个asp.net(mvc)网站.作为函数的一部分,我将不得不支持一些长时间运行的操作,例如:
从用户启动:用户可以将(xml)文件上传到服务器.在服务器上我需要提取文件,做一些操作(插入数据库)等...这可能需要一分钟到十分钟(甚至更多 - 取决于文件大小).当然我不希望在导入运行时阻止请求,但我想将用户重定向到某个进度页面,在那里他将有机会观察状态,错误甚至取消导入.
此操作不会经常使用,但可能会发生两个用户同时尝试导入数据的情况.并行运行导入会很不错.一开始我想在iis中创建一个新线程(控制器动作)并在新线程中运行导入.但我不确定这是不是一个好主意(在Web服务器上创建工作线程).我应该使用Windows服务还是其他任何方法?
从系统启动: - 我将不得不定期使用新数据更新lucene索引. - 我将不得不发送大量电子邮件(将来).
我应该将其作为网站中的工作实现并通过Quartz.net运行工作,还是应该创建Windows服务?
在运行网站"工作"时,最佳做法是什么?
谢谢!
我正在开发一个小部件,可以作为iframe嵌入到页面中(iframe将通过javascript注入和设置样式).iframe应放在右下角.我只能控制iframe的样式.
我创建了以下演示页面,演示了测试主页中的问题:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Hello world!</title>
<meta name="viewport" content="width=device-width"/>
</head>
<body>
<p id="greeting" style="width:1000px">Loading...</p>
<iframe src="http://www.w3schools.com" style="position: fixed; bottom: 5%; width: 200px; height: 200px; background: transparent; border: 0px none; overflow: hidden; z-index: 1000000;right: 5%;"></iframe>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
在桌面浏览器上,此代码可以正常工作,但在(某些)移动设备上,iframe在屏幕上不可见.如果我尝试突出显示放置在灰色区域的元素.
为什么会发生这种情况,如何设置iframe样式以便放置在右下角?
编辑:这是来自Galaxy S3仿真(Chrome)的屏幕截图.iframe在灰色区域是不可见的.我认为它在物理Nexus 5X设备上是一样的.
非常感谢!
我有以下课程:
MyClass
public virtual int Id { get; set; }
public virtual int Code { get; set; }
public virtual int Description { get; set; }
public virtual int Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
使用以下映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TestApplication" assembly="TestApplication">
<class name="MyClass" table="MyTable">
<id name="Id" column="id">
<generator class="native"/>
</id>
<property name="Code" column="code"/>
<property name="Description" column="description"/>
<property name="Name" formula="(SELECT b.translation FROM translations b WHERE b.translation_id = translation_id AND b.language_id = :TranslationFilter.LanguageId)"/>
</class>
<filter-def name="TranslationFilter">
<filter-param name="LanguageId" type="Int32"/>
</filter-def> …Run Code Online (Sandbox Code Playgroud) 我在SQL Server 2008(SP2)中有一个表,包含3000万行,表大小为150GB,有几个int列和两个nvarchar(max)列:一列包含文本(1-30000个字符),另一个包含xml(最多100000个字符).
表没有任何主键或索引(它是临时表).所以我正在运行一个查询:
UPDATE [dbo].[stage_table]
SET [column2] = SUBSTRING([column1], 1, CHARINDEX('.', [column1])-1);
Run Code Online (Sandbox Code Playgroud)
查询运行了3个小时(并且仍未完成),我认为这个时间太长了.是吗?我可以看到.mdf文件的读取速率为5MB/s,写入速率为10MB/s.
如何找出查询运行这么久的原因?"服务器"是RAID 10上的i7,24GB RAM,SATA磁盘.
更新:
table包含一个int列,两个nvarchar(20)列和两个nvarchar(max)列.上面的update子句中的Column1和Columns2是nvarchar(20)列."大"列未更新.
非常感谢!
我有一个 ASP.NET MVC 项目,它使用实体框架、SignalR 和 Hangfire 作业。
我的主(根)容器是这样定义的:
builder.RegisterType<DbContext>().InstancePerLifetimeScope(); // EF Db Context
builder.RegisterType<ChatService>().As<IChatService>().SingleInstance(); // classic "service", has dependency on DbContext
builder.RegisterType<ChatHub>().ExternallyOwned(); // SignalR hub
builder.RegisterType<UpdateStatusesJob>().InstancePerDependency(); // Hangfire job
builder.RegisterType<HomeController>().InstancePerRequest(); // ASP.NET MVC controller
IContainer container = builder.Build();
Run Code Online (Sandbox Code Playgroud)
对于 MVC,我使用 Autofac.MVC5 nuget 包。依赖解析器:
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
Run Code Online (Sandbox Code Playgroud)
对于 SignalR,我使用 Autofac.SignalR nuget 包。依赖解析器:
GlobalHost.DependencyResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container);
Run Code Online (Sandbox Code Playgroud)
我的signalR集线器以这种方式实例化(http://autofac.readthedocs.org/en/latest/integration/signalr.html#managing-dependency-lifetimes):
private ILifetimeScope _hubScope;
protected IChatService ChatService;
public ChatHub(ILifetimeScope scope) {
_hubScope = scope.BeginLifetimeScope(); // scope
ChatService = _hubScope.Resolve<IChatService>(); // this service is used …Run Code Online (Sandbox Code Playgroud) 作为我们应用程序的一部分,我需要编写"简单"的工作流系统,该系统将用于支持文档创建生命周期.它应该支持: - 不同的活动:编辑文档,验证文档(批准,拒绝),发布文档...... - 将此活动分配给不同的人/用户 - "并行拆分和加入".例如,我想支持这样的工作流程:
- begin
1.) Create document
2.) Translate document
2.1) Translate into English
2.1.1) Translate document into English
2.1.2) Verify English translation
2.2) Translate into Italian
2.2.1) Translate document into Italian
2.2.2) Verify Italian translation
3.) Verify complete document
4.) Publish document
- end
Run Code Online (Sandbox Code Playgroud)
它将用于asp.net应用程序(C#).
最后一部分:我想知道是否有任何模式,库或文章可以帮助我开始这项任务?世界自然基金会是否适合这个?
有一些材料(甚至在stackoverflow上),但我不知道如何处理并行性?
我有两个包含以下数据的表:
Test_parent:
parent_id title
------------------
1 Parent1
2 Parent2
3 Parent3
4 Parent4
Run Code Online (Sandbox Code Playgroud)
Test_child:
child_id parent_id property
------------------------------------
1 1 A
2 2 A
3 2 B
4 3 A
5 3 C
6 4 A
Run Code Online (Sandbox Code Playgroud)
我想从表test_parent中选择所有行,其中parent包含具有(BOTH)属性A和B的子项(所以这将是parent_id = 2的记录)
这是我到目前为止写的最佳解决方案:
select *
from test_parent p
where (select COUNT(property)
from test_child c
where p.parent_id = c.parent_id and c.property in ('A', 'B')) = 2
Run Code Online (Sandbox Code Playgroud)
还有更"正确"的方式吗?
非常感谢!
这是对象的完整脚本:
CREATE TABLE [dbo].[test_parent](
[parent_id] [int] IDENTITY(1,1) NOT NULL,
[title] [nvarchar](50) NOT NULL,
CONSTRAINT …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×2
sql ×2
asp.net ×1
autofac ×1
css ×1
hangfire ×1
hibernate ×1
html ×1
mobile ×1
mvvm ×1
nhibernate ×1
signalr ×1
silverlight ×1
sql-server ×1
t-sql ×1
workflow ×1