小编Lan*_*ond的帖子

如何卸载程序而不重新启动

我编写了一个程序,使用C#中的ManagementObject自动卸载许多程序.它工作正常,除了一些程序自动重启计算机,这违背了我的程序的目的.有什么方法可以让它等到一切都完成卸载重启?

以下是实际卸载程序的方法:

static void UninstallProduct(string path)
{
  ManagementObject product = new ManagementObject(path);

  if ((product != null) && (product.Path.ClassName == "Win32_Product"))
  {
    Console.WriteLine(
      "Uninstalling: "
      + product.GetPropertyValue("Name")
      + "...");

    object result = product.InvokeMethod("Uninstall", null);
    Console.WriteLine(
      "The Uninstall method result is {0}",
      result.ToString());
  }
}
Run Code Online (Sandbox Code Playgroud)

c#

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

在ASP.NET MVC视图中,Newtonsoft Json.NET序列化对象无法正确呈现

我正在使用ASP.NET MVC Razor View将对象序列化为JSON.调试器中的输出是正确的,但因为它逃脱了每个引用,我认为MVC可能正在尝试对其进行编码,因为最终输出最终会像这样:

{"label":"Blowby","value":17},{"label":"BlownInsert","value":11},{"label":"Blowout","value":13},{"label":"Contamination","value":7},{"label":"CrushedInsert","value":3},{"label":"Reclaim","value":8},{"label":"ShortShot","value":4},{"label":"Sinks","value":10}
Run Code Online (Sandbox Code Playgroud)

json格式正是我想要的,但不是"它需要实际的引号".我没试过HtmlUtilites.HtmlDecode().我该如何修复输出?

如果它有帮助,这里有更多的代码,这是在.cshtml/Razor文件中.

 List<LightSwitchApplication.Models.GraphData> DonutGraphData = (List<LightSwitchApplication.Models.GraphData>)ViewData["DonutGraphData"];
string donutSerialized = Newtonsoft.Json.JsonConvert.SerializeObject(DonutGraphData);
Run Code Online (Sandbox Code Playgroud)

和GraphData类:

namespace LightSwitchApplication.Models
{
public class GraphData
{
    public string label { get; set; }
    public int value { get; set; }

    public GraphData(string label, int value)
    {
        this.label = label;
        this.value = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

}

并且实际变量输出到View:

if ($('#donut-graph').length) {
            Morris.Donut({
                element: 'donut-graph',
                data: @donutSerialized,
                formatter: function (x) {
                    return x
                }
            });
        }
Run Code Online (Sandbox Code Playgroud)

以下是调试器中donutSerialized的输出:

"[{\"label\":\"Blowby\",\"value\":17},{\"label\":\"BlownInsert\",\"value\":11},{\"label\":\"Blowout\",\"value\":13},{\"label\":\"Contamination\",\"value\":7},{\"label\":\"CrushedInsert\",\"value\":3},{\"label\":\"Reclaim\",\"value\":8},{\"label\":\"ShortShot\",\"value\":4},{\"label\":\"Sinks\",\"value\":10}]"
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc json json.net

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

标签 统计

c# ×2

asp.net ×1

asp.net-mvc ×1

json ×1

json.net ×1