小编Cra*_* W.的帖子

ASP.NET MVC如何在@ HTML.ActionLink中插入其他html元素

通常,我会写这样的东西:

<li>@Html.ActionLink("Dashboard", "Index", "Account")</li>
Run Code Online (Sandbox Code Playgroud)

要生成这个:

<a href="/Account">Dashboard</a>
Run Code Online (Sandbox Code Playgroud)

我想知道的是是否可以生成以下HTML

<a href="#"><i class="fa fa-dashboard"></i> Dashboard</a>
Run Code Online (Sandbox Code Playgroud)

无需创建自己的自定义TagBuilder类.

谢谢您的帮助.

asp.net-mvc razor c#-4.0 asp.net-mvc-4

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

使用带有 null 返回值的 LINQ let

我正在尝试在 LINQ 中执行一个方法

var result = from fruit in fruits
             let type = GetType(fruit)
             select new {
                 fruit = fruit,
                 type = type != null ? type.Name : "N/A"
             };

FruitType GetType(Fruit fruit)
{
    if (fruit == a)
      return TypeA;
    else 
      return null;
}
Run Code Online (Sandbox Code Playgroud)

这会引发错误,因为: if resultis null,即使在检查之后也let不允许访问。type.Namenot null

有什么解决方法吗?

.net c# linq asp.net-mvc let

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

Linq查询 - 返回一个总和

我无法弄清楚如何做以下事情.这纯粹是伪代码:

decimal totalActiveCost = (from i in _context.KeyActives 
                           where i.Pk in (active1fk, active2fk, active3fk, active4fk, active5fk, keyActiveFk) 
                           select sum(i.Cost)...`
Run Code Online (Sandbox Code Playgroud)

然后总结i.Cost.所以基本上,我需要为每个"活动"返回i.Cost - 例如,假设active1fk为1,active2fk为2,依此类推.我需要为每一个获得成本并总结它们.

c# sql linq

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

ToList()查询之前的代码差异

这种方法有什么区别

public List<CollegeAddress> GetAllAddress()
{
    return collegeAppContext.CollegeAddresses.ToList().Where(x => x.StateId == 4);
}
Run Code Online (Sandbox Code Playgroud)

public List<CollegeAddress> GetAllAddress()
{
    return collegeAppContext.CollegeAddresses.Where(x => x.StateId == 4).ToList();
}  
Run Code Online (Sandbox Code Playgroud)

哪一种方法是标准代码?(但我的第一种方法扔了交谈错误:)

有什么区别?

c# comparison performance standards entity-framework

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

LINQ to Entities无法使用某些功能?

我正在尝试使用LINQ查询在项目上实现搜索功能.因为数据有时包含带有重音符号和其他符号的字符,所以我创建了一种方法来删除这些符号以进行搜索.

这是我的代码:

var addresses = (from a in db.Addresses
                 join b in db.Addresses on a.ClientID equals b.ClientID
                 where a.AddressType == 1 && b.AddressType == 2
                 select new
                 {
                     /* Columns selected */
                 });
var q = (from e in db.Employers
         join a in addresses on e.EmployerID equals a.id
         join i in db.IndustrialSectors on e.IndustrialSector equals i.ID
         select new
         {
             /* Columns selected */
         });

if (search != "")
{
    q = (from i in q
         where (
           Util.StringUtil.RemoveDiacritics(i.entity.ToString().ToLowerInvariant()).Contains(search) ||
           Util.StringUtil.RemoveDiacritics(i.name.ToString().ToLowerInvariant()).Contains(search) …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

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

连接池已耗尽

使用并行将数据插入数据库时foreach,出现以下错误:

连接池已耗尽'

将一些数据插入数据库后

try
{
    var connection = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;

    Parallel.ForEach(Enumerable.Range(0, 1000), (_) =>
    {
        using (var connectio = new NpgsqlConnection(connection))
        {
            connectio.Open();
            using (var command = new NpgsqlCommand("fn_tetsdata", connectio) { CommandType = CommandType.StoredProcedure })
            {
                command.Parameters.AddWithValue("firstname", "test");
                command.Parameters.AddWithValue("lastname", "test");
                command.Parameters.AddWithValue("id", 10);
                command.Parameters.AddWithValue("designation", "test");

                command.ExecuteNonQuery();
            }
            connectio.Close();
        }
    });
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)

c# npgsql

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

C#消息框出现两次

我正在尝试做一个简单的魔兽世界头像"提取器".这是我的代码:

private void pictureBox1_Click(object sender, EventArgs e)
{
    if (textBox4.Text != "")
    {
        webBrowser1.ScriptErrorsSuppressed = true;
        webBrowser1.Navigate("https://worldofwarcraft.com/en-gb/search?q=" + textBox4.Text);
        webBrowser1.DocumentCompleted += GetImg;
    }
}
private void GetImg(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    string result = "";
    foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div"))
        if (el.GetAttribute("className") == "Avatar-image")
        {
            result = (el.OuterHtml).Substring(el.OuterHtml.IndexOf("https"));
            result = result.Substring(0, result.IndexOf(")"));
            pictureBox1.ImageLocation = result;
            DialogResult YESNO = MessageBox.Show("Is this your character?", "Select your char", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (YESNO == DialogResult.Yes)
            {
                break;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是我单击图像一次,如果字符是正确的,我点击"是",一切都很好.但是,如果我第二次单击图像弹出消息框,那么我选择了我的答案但是再次弹出消息框.如果我第三次点击图片,消息框将出现3次......有什么想法吗?

c# oop messagebox

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

C#:我的Else语句被陷入阵中,我怎么忽略它?

我有这个代码的麻烦,我想拥有的代码返回一个答案,如果输入列表中的项目相匹配,(不能使用数组),或者如果没有匹配,写行一次,重复代码,但是当我这样做时,结果是:

Please enter the type of gem you want on your wedding ring:
diamond
Im sorry that was not a valid selection.
Im sorry that was not a valid selection.
Im sorry that was not a valid selection.
Your wedding ring will feature your selection: diamond
Im sorry that was not a valid selection.
Im sorry that was not a valid selection.
Run Code Online (Sandbox Code Playgroud)

代码是;

List<string> Gems = new List<string>();
Gems.Add("ruby");
Gems.Add("emerald");
Gems.Add("topaz");
Gems.Add("diamond");
Gems.Add("pearl");
Gems.Add("infinity stone");
Console.WriteLine("Please enter the …
Run Code Online (Sandbox Code Playgroud)

c# if-statement list

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

无法从“System.Windows.Forms.MessageBoxButtons”转换为“string”

无法从“System.Windows.Forms.MessageBoxButtons”转换为“string”

我不知道

MessageBox.Show("Problem generating the quiz.Sorry!", MessageBoxButtons.OK, MessageBoxIcon.Error

Random rdmNumber = new Random();
number1 = rdmNumber.Next(0, 10);
number2 = rdmNumber.Next(0, 10);
int selectOp = rdmNumber.Next(0, 4);
operation = "";
switch (selectOp)
{
    case 1:
        operation = " + ";
        solution = number1 + number2;
        break;
    case 2:
        operation = " - ";
        if (number1 < number2)
        {
            int temp = number1;
            number1 = number2;
            number2 = temp;
        }
        solution = number1 - number2;
        break;
    case 3:
        operation = " x …
Run Code Online (Sandbox Code Playgroud)

c# messagebox winforms

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

"意外的符号`else'"如何修复此问题(if语句后没有分号)?

我在第56行收到错误...有人可以告诉我为什么吗?我没有在if语句的末尾添加任何分号,我也使用右括号放置......这里有什么问题?我将不胜感激,谢谢!

这是我的代码:

using UnityEngine;
using System.Collections;

public class PlayerPrefsManager : MonoBehaviour {

    const string MASTER_VOLUME_KEY = "master_volume";
    const string DIFFICULTY_KEY = "difficulty";
    const string LEVEL_KEY = "level_unlocked_";

    public static void SetMasterVolume(float volume)
    {
        if (volume > 0f && volume < 1f) {

            PlayerPrefs.SetFloat (MASTER_VOLUME_KEY, volume);

        } else {

            Debug.LogError ("Master volume out of range");

        }
    }

    public static float GetMasterVolume()
    {
        return PlayerPrefs.GetFloat (MASTER_VOLUME_KEY);
    }

    public static void UnlockLevel (int level)
    {
        if (level <= Application.levelCount - 1) {

            PlayerPrefs.SetInt(LEVEL_KEY …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

-8
推荐指数
1
解决办法
205
查看次数