小编Pet*_*ter的帖子

Ajax.BeginForm替换了下拉列表的整个页面

目的

我有一个简单的表列出名称(在部分视图中),上面是一个包含这些名称的下拉列表.目的是根据下拉列表中选择的名称过滤表.只要下拉列表中的选定值发生更改,就应该进行过滤,并且应该仅再次呈现部分视图.

问题

当我在下拉列表中选择一个值时,部分视图不会在另一个视图中呈现,而是显示为整个页面.但是,当我在Ajax.BeginForm块中包含一个提交按钮,并在提交按钮上触发操作时,它确实按预期运行...

代码

调节器

public PartialViewResult Filter(string filterName) {
    var names = from p in db.People
                select p;

    if (!String.IsNullOrEmpty(filterName))
    {
        names = names.Where(p => p.Name.Equals(filterName));
    }

    return PartialView("_PersonsTable", names);
}
Run Code Online (Sandbox Code Playgroud)

视图

@model IEnumerable<Sandbox.Models.Person>

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

@using (Ajax.BeginForm("Filter", "Person", new AjaxOptions { 
    HttpMethod = "Get", UpdateTargetId = "SearchResults", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace }))
{
    @Html.DropDownList("filterName", new SelectList(ViewBag.Names), "Select a name", new   { onchange = "this.form.submit()" })
}

@Html.Partial("_PersonsTable")
Run Code Online (Sandbox Code Playgroud)

局部视图

@model IEnumerable<Sandbox.Models.Person>

<table id="SearchResults">
    <tr>
        <th> …
Run Code Online (Sandbox Code Playgroud)

ajax asp.net-mvc razor

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

在DAL层中使用appsettings

我有一个winforms应用程序,其中一些数据存储在XML文件中.应存储这些XML文件的位置可由用户配置,并存储在AppSettings中.我的所有图层都是单独的组件.我可以从我的DAL程序集中访问我的设置,还是应该将其作为参数传递到我的所有图层?

当我尝试从DAL层读取设置时,我遇到了另一个问题

        Configuration config = ConfigurationManager.OpenExeConfiguration(
            System.Reflection.Assembly.GetEntryAssembly().Location);
        string dataStorageLocation = config.AppSettings["DataStorageLocation"];
Run Code Online (Sandbox Code Playgroud)

config.AppSettings ["DataStorageLocation"]给出编译错误:System.Configuration.ConfigurationElement.this [System.Configuration.ConfigurationProperty]由于其保护级别而无法访问.这是为什么?

有人能让我走上正轨吗?谢谢.

c# appsettings winforms

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

如何在 Github-Flavoured-Markdown 中添加元数据?

我想将元数据信息添加到我的 Markdown 文件中,例如作者、标签等。是否可以像使用multimarkdown一样将元数据添加到 github-flavoured-markdown 文件中?

markdown multimarkdown github-flavored-markdown

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

为什么我的项目连接到不同的数据源?

我有2个解决方案,使用EF 6.0,并且都使用完全相同的默认配置。它们仍然连接到2个不同的数据源!(localdb)\ mssqllocaldb和。\ SQLEXPRESS。

我的配置:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
Run Code Online (Sandbox Code Playgroud)

两者的DbContext也相似:

public class PlusUltraContext : DbContext
{
    public PlusUltraContext() : base("PlusUltra")
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        base.OnModelCreating(modelBuilder);
    }

    public DbSet<Models.Article> Articles { get; set; }
    public DbSet<Models.ArticleComment> Comments { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

public class InvoicingContext : DbContext
{
    public DbSet<Address> Addresses { get; set; }
    public DbSet<Company> Companies { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# sql-server entity-framework

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

从列表中创建和初始化字典

有没有办法将下面两个语句合并为一个,所以你可以在一个语句中从一个数组创建和初始化一个字典?

var myDictionary = new Dictionary<int, string>();
myList.ForEach(i => myDictionary.Add(i.property1, i.property2));
Run Code Online (Sandbox Code Playgroud)

(是否使代码更容易阅读是另一个主题:-))

c# linq

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