将 html 操作链接添加到实体框架 Code First AddModelError 字符串

发布于 2024-11-15 01:00:51 字数 689 浏览 3 评论 0原文

我对编程还很陌生,如果我很愚蠢,很抱歉,但我正在编写一个 ASP.Net MVC3 应用程序,其中如果捕获到特定异常,则会显示一条消息,因为复合键冲突。

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

我无法弄清楚如何在以下示例中使用链接。如何使“此处”成为操作链接?

            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");
                }

谢谢...

I am pretty new to programming so sorry if I'm being stupid, but I am writing an ASP.Net MVC3 application in which, if a particular exception is caught a message is displayed because of a composite key violation.

I can catch the exception but in the message I want to add an action link to edit the data that has failed the key violation test.

I can't work out how to use a link in following example. How can I make "HERE" an action link?

            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");
                }

Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-11-22 01:00:51

您是否尝试过更改错误以仅输出链接的原始 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>");
            }

到目前为止您尝试过什么?

Have you tried changing the Error to just output the raw HTML for the link like this:

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>");
            }

What have you tried so far?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文