小编JK.*_*JK.的帖子

ASP.NET MVC Html.Display()使用ViewData?

当我使用Html.DisplayFor()使用模型的属性时,它很好地与属性名称的标签和具有属性值的文本框或标签:

Html.DisplayFor(model => model.FirstName)     // renders as First Name: Joe Smith
Run Code Online (Sandbox Code Playgroud)

但是如果我尝试在ViewData中使用相同的东西,它似乎没有任何方法来指定将在渲染的html中的标签中使用的文本:

Html.Display(ViewData["something"].ToString())     // renders as (no label) something
Run Code Online (Sandbox Code Playgroud)

其他Html.Display()参数看起来没有帮助:

Html.Display(ViewData["something"].ToString(), "TemplateName", "HtmlElementId", {additionalData})
Run Code Online (Sandbox Code Playgroud)

看起来我可能传递标签的唯一地方是使用additionalData参数,但我没有找到任何关于如何执行此操作的示例或文档.

c# asp.net-mvc

3
推荐指数
1
解决办法
2万
查看次数

SQL从执行程序中选择SUM(col)?

SQL Server(2010)中是否有一种简单的方法来执行存储过程(返回表)并在一个(或几个)语句中对一列求和?

例如

SELECT SUM(column) FROM exec proc_GetSomeStuff 'param1', 'param2'
Run Code Online (Sandbox Code Playgroud)

sql sql-server select exec

3
推荐指数
1
解决办法
4670
查看次数

ExpanderView不显示所有项目

我使用的是WindowsPhone Toolkit的ExpanderView,在第一次加载时,扩展的Expander总是看起来像第二张图片.看起来,它始终处于所有物品的同一高度.

如果我转到另一页并返回,一切都会很好,布局看起来很安静 - 除了停止扩展器的行(图1).

this.UpdatedLayout();(当前页面)或ExpanderView.UpdateLayout(); 解决了什么.未显示的项目已在该列表中完全加载.

第1部分

第2部分

<ItemsControl ItemsSource="{Binding EpisodeList}" Margin="20,0,0,0" Grid.Row="1" Grid.ColumnSpan="2">
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <StackPanel>
            <toolkit:ExpanderView ItemsSource="{Binding Value}" >
                <toolkit:ExpanderView.Header>
                    <TextBlock Margin="0,0,10,0">
            <Run Text="Season "/>
            <Run Text="{Binding Key}" />
                    </TextBlock>
                </toolkit:ExpanderView.Header>
                <toolkit:ExpanderView.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="White" BorderThickness="1" Margin="5">
                            <Grid MouseLeftButtonUp="Grid_MouseLeftButtonUp">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Image Height="40"  Source="{Binding ScreenCap}" Margin="5,0,0,0"/>
                                <TextBlock x:Name="t" Margin="10" Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1" />
                            </Grid>
                        </Border>
                    </DataTemplate>
                </toolkit:ExpanderView.ItemTemplate>

            </toolkit:ExpanderView>
        </StackPanel>
    </DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

EpisodeList是Dictionary(int,ObservableCollection(myClass))的类型,并实现了INotifyPropertyChanged

如果有人有任何计划在这里出错,我真的很感激你的帮助,我只是没有在谷歌上找到任何bug报告,也没有类似的Bug.

(在设备和仿真器上调试)

expander silverlight-toolkit windows-phone-7

3
推荐指数
1
解决办法
1761
查看次数

ASP.NET MVC2从jQuery调用AsyncController方法?

我正在尝试学习如何在MVC2中使用AsyncController,但是那里的文档/教程很少.我正在寻找一种普通的控制器方法,它对第三方服务的导出非常慢,并将其转换为异步方法.

原始控制器方法:

public JsonResult SaveSalesInvoice(SalesInvoice invoice)
{
    SaveInvoiceToDatabase(invoice); // this is very quick 
    ExportTo3rdParty(invoice); // this is very slow and should be async
}
Run Code Online (Sandbox Code Playgroud)

所以我创建了一个继承自AsyncController的新控制器:

public class BackgroundController : AsyncController
{
    public void ExportAysnc(int id)
    {
        SalesInvoice invoice = _salesService.GetById(id);
        ExportTo3rdParty(invoice);
    }

    public void ExportCompleted(int id)
    {
         // I dont care about the return value right now, 
         // because the ExportTo3rdParty() method
         // logs the result to a table
    }

    public void Hello(int id)
    {            
    }
}
Run Code Online (Sandbox Code Playgroud)

然后从jQuery调用Export方法:

function Export() …
Run Code Online (Sandbox Code Playgroud)

c# jquery asynccontroller asp.net-mvc-2

2
推荐指数
1
解决办法
2551
查看次数

ASP.NET MVC2可以通过AsyncController访问HttpContext.Current吗?

我正在尝试将此方法转换ExportTo3rdParty()为使用AsyncController:

public JsonResult SaveSalesInvoice(SalesInvoice invoice)
{
    SaveInvoiceToDatabase(invoice); // this is very quick 
    ExportTo3rdParty(invoice); // this is very slow and should be async
}
Run Code Online (Sandbox Code Playgroud)

但是ExportTo3rdParty()方法在多个地方使用HttpContext.Current(太多不能改变 - 原始编码器没有使用足够的依赖注入).例如,它调用GetDefaultCurrency().当通过AsyncController调用ExportTo3rdParty()时,这仍然有用吗?

public Currency GetDefaultCurrency()
{
    Currency currency;
    string key = string.Format("DefaultCurrency_{0}", 
                                HttpContext.Current.User.Identity.Name);
    currency = HttpRuntime.Cache.Get(key) as Currency;
    if (currency == null)
    {
        currency = LookupDefaultCurrency();
        HttpRuntime.Cache[key] = currency;
    }
} 
Run Code Online (Sandbox Code Playgroud)

我知道如果我使用Thread.Start,我无法访问HttpContext.Current.但是AsyncController怎么样?

c# jquery asynccontroller asp.net-mvc-2

2
推荐指数
1
解决办法
1150
查看次数

Visual Studio 2010 SP1中缺少MVC3

我安装了VS 2010终极版.它没有MVC3.我安装了SP1,它应该已经安装了更新以及MVC3 - 对吧?

但是在安装之后,我仍然没有新项目窗口中的MVC3选项.这有什么不对?

visual-studio-2010 asp.net-mvc-3

2
推荐指数
1
解决办法
2万
查看次数

如何获得Div的所有文本框的价值?

我有一个div容器,当我点击一个Add按钮时,我正在创建一个动态文本框控件

<div id="Container">
    <input type="Submit" id="AddTextBox" value="Add">
    <!-- Here are my dynamic textboxes -->
    <input type="text" value='' class="dynamic">
    <input type="text" value='' class="dynamic">
    <input type="text" value='' class="dynamic">
</div>

<input type="create" id="create" onclick="GetValue();" value="create">
Run Code Online (Sandbox Code Playgroud)

我想获得所有文本框控件的值,例如:

Function GetValue()
{
    var COntain=TextBoxValue+"$"+Textbox2Value+"$"; // so on
}
Run Code Online (Sandbox Code Playgroud)

jquery

2
推荐指数
1
解决办法
2万
查看次数

创建一个新的jquery链式方法

你如何在jQuery中编写新的链式方法?我的jQuery中有一个非常程序化的风格:

$("#SaveButton").click(function () {
    Foo($("#SubTotal"));
    Foo($("#TaxTotal"));
    Foo($("#Total"));
    Bar($("#SubTotal"));
    Bar($("#TaxTotal"));
    Bar($("#Total"));        
});
Run Code Online (Sandbox Code Playgroud)

如何在jQuery中创建一个.foo()方法,以便我可以编写:

$("#SaveButton").click(function () {
    $("#SubTotal,#TaxTotal,#Total").foo().bar();
});
Run Code Online (Sandbox Code Playgroud)

并在相关点-是否有一种简单的方法(在Visual Studio或记事本++或别的东西)来查找和替换所有Foo($("#selector"));$("#selector").foo();

jquery jquery-plugins method-chaining

1
推荐指数
1
解决办法
1108
查看次数

当应该有速度时,实体框架会变慢

我有一个问题,如果不应该将子对象添加到父对象异常缓慢.有成千上万个子对象(在这种情况下为33k记录),但这些对象都不是父对象的子对象.

当我将第一个孩子添加到父母时,需要一分钟以上才能完成:

public class ParentEntity // POCO generated by EF TT4 templates
{
    public virtual int Id { get; set; }
    public virtual ICollection<ChildEntity> ChildEntities  {}
} 

public class ChildEntity // POCO generated by EF TT4 templates
{
    public virtual int Id { get; set; }
    public virtual int ParentEntityId { get; set; }
    public virtual ParentEntity ParentEntity { get; set; }
    public virtual Warehouse Warehouse  { get; set; }
    public virtual WarehouseLocation  WarehouseLocation  { get; set; }
}

public …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc performance linq-to-entities entity-framework

1
推荐指数
1
解决办法
1284
查看次数

Browserswitch然后使用meta http-equiv ="X-UA-Compatible" - Documentmodus已经完成

我们对某些Internet Explorer版本有一些奇怪的问题,所以我们有一个浏览器开关

<head>
<!--[if IE 6]>
  <!-- load some IE6 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=6" />
<![endif]-->
<!--[if IE 7]>
  <!-- load some IE7 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=6" />
<![endif]-->

<!--[if IE 8]>
  <!-- load some IE8 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
<![endif]-->

<!--[if IE 9]>
  <!-- load some IE9 stuff -->
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
<![endif]-->
</head>
Run Code Online (Sandbox Code Playgroud)

如果我像这样加载它,我在IE9 Developer附加组件中看到:

HTML1115:与X-UA兼容的META-Tag("IE = 8")被忽略,因为documentmodus已经加载.

(最初是德语,所以我应该翻译)

并且文档模式仍然是IE9

如果我在我的<head>标签中写得很难:

   <meta http-equiv="X-UA-Compatible" content="IE=8" />
Run Code Online (Sandbox Code Playgroud)

IE9将作为IE8加载,所以这可行,但那时IE6的东西当然是错误的....

那么有没有办法像我第一次尝试那样做?

internet-explorer browser-detection internet-explorer-9 x-ua-compatible

1
推荐指数
1
解决办法
4327
查看次数