在BLL使用ASP.NET服务器端验证 [英] Server Side Validation in BLL using ASP.NET

查看:112
本文介绍了在BLL使用ASP.NET服务器端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用asp.net 3层架构登录电子业务层(BLL)执行服务器端验证。
我现在面临的问题是:我不知道这是什么的ModelState,什么libararies / DLL,我要补充得到它我可以product.aspx执行服务器端验证。 CS文件,但我需要做的是在BLL。
我读<一个每一个字和链接href=\"http://stackoverflow.com/questions/6225106/what-is-better-way-to-validate-business-rules-in-asp-net-mvc-application-with-3\">this问题却得到了零的帮助。请帮我在ProductBL.cs文件执行验证通过指导我怎么去的ModelState。

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.

下面是我的Product.aspx文件code:

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>

我Product.aspx.cs文件code:

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);
}

我的实体文件code:

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;}
}

我ProductBL.cs文件code:

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 
        }
    }

请帮助得到这个这个的ModelState 在使用BLL层3

推荐答案

这是好主意,但的ModelState 对象只能在asp.net中使用 MVC 应用程序。如 MSDN <描述/ A>这个对象是System.Web.Mvc的一部分。

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.

这篇关于在BLL使用ASP.NET服务器端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆