小编sha*_*oth的帖子

HTML.ActionLink方法

假设我有一堂课

public class ItemController:Controller
{
    public ActionResult Login(int id)
    {
        return View("Hi", id);
    }
}
Run Code Online (Sandbox Code Playgroud)

在不在Item文件夹中的页面上ItemController,我想创建一个指向该Login方法的链接.那么Html.ActionLink我应该使用哪种方法以及我应该传递哪些参数?

具体来说,我正在寻找替代方法

Html.ActionLink(article.Title,
    new { controller = "Articles", action = "Details",
          id = article.ArticleID })
Run Code Online (Sandbox Code Playgroud)

已经在最近的ASP.NET MVC化身中退役了.

.net c# asp.net-mvc html-helper actionlink

241
推荐指数
8
解决办法
68万
查看次数

如何删除类似const和非const成员函数之间的代码重复?

假设class X我想要返回内部成员的访问权限:

class Z
{
    // details
};

class X
{
    std::vector<Z> vecZ;

public:
    Z& Z(size_t index)
    {
        // massive amounts of code for validating index

        Z& ret = vecZ[index];

        // even more code for determining that the Z instance
        // at index is *exactly* the right sort of Z (a process
        // which involves calculating leap years in which
        // religious holidays fall on Tuesdays for
        // the next thousand years or so)

        return ret;
    }
    const …
Run Code Online (Sandbox Code Playgroud)

c++ const class code-duplication c++-faq

228
推荐指数
11
解决办法
3万
查看次数

具有键'MY KEY'的ViewData项的类型为'System.String',但必须是'IEnumerable <SelectListItem>类型的'

我试图使用ASP.NET MVC 2从使用Linq-2-SQL映射的数据库填充下拉列表,并继续收到此错误.

我很困惑,因为我IEnumerable<SelectListItem>在第二行声明了一个类型的变量,但错误让我觉得情况并非如此.我觉得这应该很简单,但我很挣扎.任何帮助表示赞赏.

以下是我的控制器的有趣内容:

public ActionResult Create()
{
    var db = new DB();
    IEnumerable<SelectListItem> basetypes = db.Basetypes.Select(
        b => new SelectListItem { Value = b.basetype, Text = b.basetype });
    ViewData["basetype"] = basetypes;
    return View();
}
Run Code Online (Sandbox Code Playgroud)

以下是我观点的有趣内容:

<div class="editor-label">
   <%: Html.LabelFor(model => model.basetype) %>
</div>
<div class="editor-field">
   <%: Html.DropDownList("basetype") %>
   <%: Html.ValidationMessageFor(model => model.basetype) %>
</div>
Run Code Online (Sandbox Code Playgroud)

这是提交表单时的POST操作

// POST: /Meals/Create
[HttpPost]
public ActionResult Create(Meal meal)
{
    if (ModelState.IsValid)
    {
        try
        {
            // TODO: Add insert logic here
            var …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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

即使你抛出一个新的异常,finally块也会运行吗?

在这个代码中,someVar即使执行catch块并抛出第二个异常,也会设置代码?

public void someFunction() throws Exception {
    try {
        //CODE HERE
    } catch (Exception e) {
        Log.e(TAG, "", e);
        throw new Exception(e);
    } finally {
        this.someVar= true;
    }
}
Run Code Online (Sandbox Code Playgroud)

java exception-handling

132
推荐指数
3
解决办法
6万
查看次数

添加List <t> .add()另一个列表

我有一个IEnumerable<TravelDetails>,我正在尝试将for-loop中的值添加到List<TravelDetails>.我一直在收到错误.

错误15参数1:无法从'System.Collections.Generic.List'转换为'TrafficCore.DataObjects.TripDetails'C:\ TrafficNew\TI 511-Web\Traffic 2.0\511Traffic\511Traffic\Models\DrivingTime.cs

我的代码是

List<TripDetails> tripDetailsCollection = new List<TripDetails>();
foreach (DrivingTimeRoute dtr in dtRoutes)
{
    foreach (Trip trip in dtr.Trips)
    {
        foreach (TripPathLink tpl in trip.TripPathLinks)
        {
            tplCollection.Add(tpl);
        }
        IEnumerable<TripDetails> tripDetails = //long Linq-to-Sql here
        List<TripDetails> td = tripDetails.ToList();
        tripDetailsCollection.Add(td); // <<< Error here
    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄这个吗.
谢谢,Pawan

.net c# linq

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

翻转布尔值的最简单方法是什么?

我只是想根据它已经是什么来翻转一个布尔值.如果这是真的 - 把它弄错.如果它是假的 - 让它成真.

这是我的代码摘录:

switch(wParam) {

case VK_F11:
  if (flipVal == true) {
     flipVal = false;
  } else {
    flipVal = true;
  }
break;

case VK_F12:
  if (otherVal == true) {
     otherValVal = false;
  } else {
    otherVal = true;
  }
break;

default:
break;
}
Run Code Online (Sandbox Code Playgroud)

c c++ boolean-logic boolean

113
推荐指数
8
解决办法
18万
查看次数

当我设置IIS池的LoadUserProfile时会发生什么?

我遇到了以下问题.

我运行以下代码

var binaryData = File.ReadAllBytes(pathToPfxFile);
var cert = new X509Certificate2(binaryData, password);
Run Code Online (Sandbox Code Playgroud)

在两个过程中.其中一个进程运行,LOCAL_SYSTEM并且此代码成功.另一个在IIS中在属于"Users"本地组的本地用户帐户下运行,在那里我得到以下异常:

System.Security.Cryptography.CryptographicException
Object was not found.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)
//my code here
Run Code Online (Sandbox Code Playgroud)

所以我用Google搜索了一下,找到了一个类似问题的答案.我尝试启用LoadUserProfile应用程序池,现在可以正常运行.

问题是我没有得到我设置时会发生LoadUserProfile什么以及可能产生的后果.我的意思是,如果它是一个"好"的东西那么为什么它不是默认"开启",为什么它毕竟在那里?

当我LoadUserProfile在IIS池中设置时会发生什么,它会产生什么负面影响?

.net c# iis-7 application-pool x509certificate

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

我可以调用memcpy()和memmove()并将"字节数"设置为零吗?

当我无法移动/复制memmove()/ memcpy()作为边缘情况时,我是否需要处理案例

int numberOfBytes = ...
if( numberOfBytes != 0 ) {
    memmove( dest, source, numberOfBytes );
}
Run Code Online (Sandbox Code Playgroud)

或者我应该在没有检查的情况下调用该函数

int numberOfBytes = ...
memmove( dest, source, numberOfBytes );
Run Code Online (Sandbox Code Playgroud)

是否需要检查前片段?

c c++ pointers memcpy memmove

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

memset()返回值有什么用?

memset()声明返回void*,它始终与传递给函数的地址相同.

返回值的用途是什么?为什么不回来void

c c++ memset

87
推荐指数
3
解决办法
7720
查看次数

"int*ptr = int()"值初始化如何不违法?

以下代码(取自此处):

int* ptr = int();
Run Code Online (Sandbox Code Playgroud)

在Visual C++中编译并对指针进行值初始化.

怎么可能?我的意思是int()产生一个类型的对象,int我不能指定int一个指针.

上面的代码如何不违法?

c++ pointers initialization built-in-types visual-c++

86
推荐指数
4
解决办法
3602
查看次数