1

I am performing server side validation on Business Loging Layer (BLL) using 3 tier architecture in asp.net. The problem I am facing is : I don't know what is this "ModelState" and what libararies/dll, I have to add for getting it. I can perform server side validation on product.aspx.cs file but I need to do it in BLL. I read each and every word and link of this question but got zero help. Kindly help me to perform validation in ProductBL.cs file by guiding me how to get ModelState.

Here is my Product.aspx file code:

<asp:Label ID="lbProductName" AssociatedControlID="txtProductName"   
runat="server">Product Name</asp:Label>
<asp:TextBox ID="txtProductName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"   
runat="server" ControlToValidate="txtProductName"   
CssClass="field-validation-error" ErrorMessage="Required">  
</asp:RequiredFieldValidator>

My Product.aspx.cs file code:

protected void btnSaveProduct_Click(object sender, EventArgs e)
{
 ProductBL productBL = new ProductBL();
 Products product = new Products();
 product.Name = txtProductName.Text;
 productBL.SaveProduct(product);
}

My Entities File code:

public partial class Products
{

    [Required(ErrorMessage = "Name is Required")]
    [StringLength(10, ErrorMessage = "Must be under 10 characters")]
    public string Name {get; set;}
}

My ProductBL.cs file code:

private ProductsDA _da = new ProductsDA();
public bool SaveProduct(Products product)
    {
        if (ModelState.IsValid)
        {
                 _da.Add(product);
                 //but don't know how to get ModelState 
        }
        else
        {
            //show the respective page/error 
        }
    }

Kindly help to got this this ModelState in BLL using 3 tier.

1
  • if you would like to validate using server side validations. then pass the variables to be validated to BLL creating an object and return the validation message. This model state and all i guess cannot be done directly in ASP.net using MODEL state unless you are using something like MVC architecture.. ie System.Web.MVC Dec 6, 2013 at 9:04

1 Answer 1

0

This is good Idea but ModelState Object can only be used in asp.net MVC Application. As described in MSDN this object is part of System.Web.Mvc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.