简体   繁体   中英

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.

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:

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM