【问题标题】:Adding an html action link to an Entity Framework Code First AddModelError string将 html 操作链接添加到 Entity Framework Code First AddModelError 字符串
【发布时间】:2011-06-11 22:05:48
【问题描述】:

我对编程很陌生,如果我很愚蠢,很抱歉,但我正在编写一个 ASP.Net MVC3 应用程序,如果捕获到特定异常,则会由于复合键违规而显示一条消息。

我可以捕捉到异常,但我想在消息中添加一个操作链接来编辑未通过密钥违规测试的数据。

我不知道如何在以下示例中使用链接。如何将“HERE”设为操作链接?

            catch (DataException)
            {
                if (duplicateKeyAttempt == true)
                {
                    ModelState.AddModelError("", "A delivery charge already exists for this combination of customer type and delivery method. " +
                        "Please check the information you have provided, this selection cannot be saved. " +
                        "If you want to edit the existing database entry, click HERE");
                }

谢谢...

【问题讨论】:

    标签: c# asp.net-mvc-3 entity-framework-4 code-first html.actionlink


    【解决方案1】:

    您是否尝试过将错误更改为仅输出链接的原始 HTML,如下所示:

    if (duplicateKeyAttempt == true)
                {
                    ModelState.AddModelError("", "A delivery charge already exists for this combination of customer type and delivery method. " +
                        "Please check the information you have provided, this selection cannot be saved. " +
                        "If you want to edit the existing database entry, click <a href=\"url\">HERE</a>");
                }
    

    到目前为止,您尝试了什么?

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2023-04-09
      • 2012-04-03
      相关资源
      最近更新 更多