Question

My business web application will have a lot of input controls where the user is expected to enter some kind of code (Country, Zip, Employee ID, etc.).

I'm using RemoteAttribute to validate code entries against my database to ensure that users entered the correct code.

The thing is, my standard feature should be to display a name of entered code if the remote validation is successful or error if the validation is not successful.

I'm not sure how to do this.

The obvious answer is to send Name property along with true value in Json object which jquery unobtrusive validation requires. The cshtml could look something like this:

@Html.LabelFor(m => m.Country)
@Html.EditorFor(m => m.Country, new { data-codename-label="lbnCountry" })
<label ID="lbnCountry"></label>

I'm not sure how to implement such an idea though. Any help is appreciated.

Was it helpful?

Solution

Take a look at this answer which should work for you as well. Do something on success response for remote validation in mvc

If in that example you choose not to send your value through the custom response header, you can always modify the javascript to do an ajax call to an action/webapi that will return the value in question after a successful validation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top