Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique validation
Message
 
 
General information
Forum:
ASP.NET
Category:
MVC
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01560641
Message ID:
01560821
Views:
44
>>Hi Viv,
>>
>>This doesn't seem to work for me. I am getting null being sent to the controller's method instead of the value I typed.
>>
>>Here is what I see when I inspect this element in Opera:
>>
>>
>><div class="editor-field" style="background-color: rgb(242, 250, 237);">
>><input class="text-box single-line valid" data-bind="value: Name" data-val="true" 
>>data-val-remote="Client Name already exists. Please enter a different Client Name." 
>>data-val-remote-additionalfields="*.Name" data-val-remote-type="POST" 
>>data-val-remote-url="/Client/doesClientNameExist" 
>>data-val-required="The Client Name field is required." id="Name" name="Client.Name" type="text" value=""/>ev
>><span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"/>
>>
>>
>>Could the problem be that the Id is "Name" but the name is "Client.Name"
>>
>>?
>Don't know why id is "Client.Name" but make sure that the parameter name in the validation method exactly matches the control id. i.e.:
public JsonResult doesClientNameExist(string Name)
>    {
>    }
If it doesn't you will get null for sure....

I have another question. I found that when I open the Edit form, the validation fire right away.

I am not sure why does it happen and how to prevent it. Also, for the edit I only want to check for uniqueness if there is another id with the same client no.

So, this is what I tried - in the Edit method (Get version) of the controller I set ViewBag.ClientID = id; and I changed my methods to be
[HttpPost]
        public JsonResult doesClientNoExist(Int16 Number)
        {
            bool result = false;
            
            if (ViewBag.ClientId !=null)

            { 
                int id = ViewBag.ClientId;
                result= Db.Clients.Any(c => c.Number == Number && c.Id !=id);
            }
            else
                result= Db.Clients.Any(c => c.Number == Number) ;

            return Json((!result), JsonRequestBehavior.AllowGet);
        }
However, ViewBag.ClientId returns null and so immediately after I fire that form it comes up with the Client No aleady exists message.

Do you see how can I solve this problem?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform