[CLOSED] MVC RAZOR VALIDATION help

  1. #1

    [CLOSED] MVC RAZOR VALIDATION help

    Hi there,

    I definitely need some examples or even possibilities on how to do
    validation with MVC RAZOR. Anything would be nice. In the SVN 2.1
    examples there's nothing I could find. So, I take everything related to
    this. I have to do a massive validation thing for a client over the weekend.
    So, if anyone could help me, I'll send you some german beer ;)

    Regards,
    Holger
    PS: MVC4, RAZOR, EF5, ext.net 2.1 SVN
    Last edited by Daniil; Oct 18, 2012 at 1:12 PM. Reason: [CLOSED]
  2. #2
    Hi Holger,

    Please provide more details about the requirement.

    "Validations" sounds too general.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi Holger,

    Please provide more details about the requirement.

    "Validations" sounds too general.
    That's quite true ;) so let's define what I'm thinking about:

    I have some fields let's say field1_id, field_2_id and field 3_id that
    are simple textfields with these id's.

    I want to validate with DirectEvent or at least s.th similar, because I have
    to do some database operations in the background (searching, if the value
    exists and so on).

    So, normal DirectEvent validation looks like the following (I know, that I
    shouldn't use control ;)

                                                        .Control(c =>
                                                        {
                                                            c.IsRemoteValidation = true;
                                                            c.RemoteValidation.Url = "/Home/is_field3_id_Valid";
                                                            c.RemoteValidation.Method = Ext.Net.HttpMethod.POST;
                                                            c.RemoteValidation.EventOwner = ValidationEventOwner.Field;
                                                            c.RemoteValidation.ValidationEvent = "select";
                                                            c.MsgTarget = MessageTarget.Under;
                                                        }
    And that's what I want to achieve :
    I want to pass several values from several textfields or grids or datefields to pass to the logic, that decides,
    if the value is 'valid'.
    So, I'm quite sure, this is possible with Javascript. To concatenate values with a Javascript function and pass
    them to ...... what ? And how ? Or is there a possibility to do it simpler ?

           public JsonResult is_field_3_id_Valid(string valueFromField_1_id,string valueFromField_2_id, string valueFromField_3_id)
            {
                JsonResult result = new JsonResult();
                if((valueFromField_1_id == "blaa") && (valueFromField_2_id == "blubbbb") && (valueFromField_3_id == "blaa"))
                ......................
                return result;
            }
    The other question is, how can I collect all validation warnings in one field.

    Regards,
    Holger
  4. #4
    Thank you for the details.

    Not sure, but, maybe, you need a FieldContainer with CombineErrors.

    Please look at the example.It is on WebForm, but the same is possible on Razor. Just to demonstrate the idea. Try to cause validation of the both fields, you will see a combined error message.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
        
    <script runat="server">
        protected void CheckField(object sender, RemoteValidationEventArgs e)
        {
            TextField field = (TextField)sender;
            
            if (field.Text == "Valid")
            {
                e.Success = true;
            }
            else
            {
                e.Success = false;
                e.ErrorMessage = "'Valid' is valid value only";
            }
    
            System.Threading.Thread.Sleep(1000);          
        }
    
        protected void CheckCombo(object sender, RemoteValidationEventArgs e)
        {
            ComboBox combo = (ComboBox)sender;
    
            if (combo.SelectedItem.Value == "2")
            {
                e.Success = true;
            }
            else
            {
                e.Success = false;
                e.ErrorMessage = "'Valid' is valid value only";
            }
    
            System.Threading.Thread.Sleep(1000);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Remote Validation - Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
           
            <ext:FormPanel 
                runat="server" 
                Title="Remote Validation Form" 
                MonitorValid="true"
                Width="300"             
                DefaultAnchor="100%"
                Height="150">
                <Items>
                    <ext:FieldContainer runat="server" CombineErrors="true" MsgTarget="Under">
                        <Items>
                            <ext:TextField runat="server" FieldLabel="TextField" IsRemoteValidation="true">
                                <RemoteValidation OnValidation="CheckField" />
                            </ext:TextField>
                    
                            <ext:ComboBox 
                                runat="server"                     
                                AllowBlank="false"
                                Editable="false" 
                                FieldLabel="ComboBox"                     
                                IsRemoteValidation="true">
                              <RemoteValidation OnValidation="CheckCombo" ValidationEvent="select" EventOwner="Field" />
                              <Items>
                                  <ext:ListItem Text="Invalid" Value="1" />
                                  <ext:ListItem Text="Valid" Value="2" />
                              </Items>
                            </ext:ComboBox>    
                        </Items>
                    </ext:FieldContainer>
                </Items>
                <Buttons>
                    <ext:Button ID="Button1" runat="server" Text="Submit" Disabled="true" />
                </Buttons>
                <Listeners>                
                    <ValidityChange Handler="#{Button1}.setDisabled(!valid);" />
                </Listeners>
           </ext:FormPanel>
        </form>    
    </body>
    </html>
  5. #5
    There is also the ModelStateStore class in MVC that you can use. Please look at the example in SVN.
    [CODE]Ext.Net.MVC.Examples\Models\Model_State\/CODE]

Similar Threads

  1. [CLOSED] [RAZOR] DraggablePanelConfig doesn't have StartDrag in Razor
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 28, 2012, 2:37 PM
  2. [CLOSED] [Razor] HyperLink Text in Razor
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 20, 2012, 12:16 PM
  3. [CLOSED] [Razor] Add GridView to GridPanel in razor
    By boris in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: May 09, 2012, 4:23 PM
  4. [CLOSED] [Razor] Setup Auto load panel in razor
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 27, 2012, 10:54 AM
  5. Replies: 3
    Last Post: Jul 11, 2011, 9:43 AM

Tags for this Thread

Posting Permissions