MattyD
MattyD

Reputation: 1

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...

Upvotes: 0

Views: 588

Answers (1)

Rondel
Rondel

Reputation: 4951

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?

Upvotes: 1

Related Questions