[CLOSED] Remote validation for textfield in MVC project

  1. #1

    [CLOSED] Remote validation for textfield in MVC project

    Hello:

    I try to do the remote validation for textfield in MVC project. When I input something, the remote validation do fired. But when the validation finished I always get a request error message from my controller.

    here is the textfield markup
    <ext:TextField ID="textField" Width="270" MaxLength="50" MinLength="4" AllowBlank="false"
       runat="server" FieldLabel="Name:"
       ValidateOnBlur="true" MsgTarget="Qtip" Text="Name Validation Test" 
       BlankText="You must input the name." IsRemoteValidation="true">
       <RemoteValidation Url="~/Controller/CheckName" Json="true">
       </RemoteValidation>
    </ext:TextField>
    the action method in controller
            public AjaxResult CheckName(string value)
            {
                AjaxResult result = new AjaxResult();
                result.ErrorMessage = "validation failed";
                return result;
            }
    I am not quite sure the return type and value is correct. Maybe that causes the error.
    Could you please have a look to see what cause the error?

    Thnk you
    Last edited by Daniil; Jul 08, 2011 at 12:07 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please use this
    var res = new JsonResult(); 
    res.Data = new { valid = false, message = "Error!" };
    return res;
  3. #3
    Hi,

    I can suggest you to return a JsonResult instance from a controller action.

    Example View

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head runat="server">
        <title>Ext.Net.MVC Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:FormPanel runat="server">
            <Items>
                <ext:TextField 
                    runat="server" 
                    FieldLabel="Type something" 
                    IsRemoteValidation="true">
                    <RemoteValidation 
                        Url="/Home/TestValidation" 
                        Method="POST" />
                </ext:TextField>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    Example Controller Action

    public JsonResult TestValidation(string value)
    {
        return new JsonResult
        {
            Data = new
            {
                serviceResponse = new
                {
                    message = value,
                    success = false
                }
            }
        };  
    }
    See also
    http://forums.ext.net/showthread.php?11666
  4. #4
    Quote Originally Posted by Daniil View Post
    Hi,

    I can suggest you to return a JsonResult instance from a controller action.

    Example View

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head runat="server">
        <title>Ext.Net.MVC Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:FormPanel runat="server">
            <Items>
                <ext:TextField 
                    runat="server" 
                    FieldLabel="Type something" 
                    IsRemoteValidation="true">
                    <RemoteValidation 
                        Url="/Home/TestValidation" 
                        Method="POST" />
                </ext:TextField>
            </Items>
        </ext:FormPanel>
    </body>
    </html>
    Example Controller Action

    public JsonResult TestValidation(string value)
    {
        return new JsonResult
        {
            Data = new
            {
                serviceResponse = new
                {
                    message = value,
                    success = false
                }
            }
        };  
    }
    See also
    http://forums.ext.net/showthread.php?11666
    It works. Thank you

Similar Threads

  1. [CLOSED] Remote validation question
    By bogc in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: May 09, 2012, 2:16 PM
  2. Replies: 3
    Last Post: Jul 11, 2011, 9:43 AM
  3. Replies: 0
    Last Post: Jun 30, 2011, 5:07 PM
  4. [CLOSED] Remote validation initial value
    By Leonid_Veriga in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 27, 2010, 7:37 AM
  5. Remote Validation
    By olimpia in forum 1.x Help
    Replies: 0
    Last Post: Jun 12, 2009, 7:39 PM

Tags for this Thread

Posting Permissions