将html操作链接添加到Entity Framework Code First AddModelError字符串

时间:2011-06-11 22:05:48

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

我是编程的新手,很抱歉,如果我是愚蠢的,但我正在编写一个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");
                }

...谢谢

1 个答案:

答案 0 :(得分: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>");
            }

到目前为止你尝试了什么?