[英]Adding an html action link to an Entity Framework Code First AddModelError string
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.如果我很愚蠢,我对编程很抱歉,但我正在编写一个 ASP.Net MVC3 应用程序,如果捕获到特定异常,则会由于复合键违规而显示一条消息。
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...谢谢...
Have you tried changing the Error to just output the raw HTML for the link like this:您是否尝试将错误更改为仅 output 原始 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>");
}
What have you tried so far?你试过什么了?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.