仅提交填写的文本框 - C#ASP.Net

时间:2017-02-07 08:06:38

标签: javascript c# jquery asp.net

目标状态

我有一个WebGrid包含多个TextBox,可以填写,但不一定非必须。因此,为了防止每行中的保存按钮我只使用一个,所以Javascript接管验证并仅返回填充的TextBox的值。

但是在验证并将填好的文本框传递给函数SaveChanges时,我遇到了一些Javascript问题。

WebGrid

此WebGrid包含一些行,每行包含三个文本框。

WebGrid grid1 = new WebGrid(Model.StamfordRel, canPage: false, fieldNamePrefix: "g1", pageFieldName: "p1");

@grid1.GetHtml(
    headerStyle: "wg_header",
    columns: new[] {

        grid1.Column("GLUSDBT1_deploydate",
            header: "GLUSDBT1 Deploydate " + Html.SortDirection(ref grid1,"GLUSDBT1_deploydate"),
            format: (item) => Html.TextBox("GLUSDBT1", (object)item.GLUSDBT1_deploydate, htmlAttributes: new { @class = "GLUSDBT1TxtBx"}),
            style: "width_deploydates"),

        grid1.Column("GLUSDBR1_deploydate",
            header: "GLUSDBR1 Deploydate " + Html.SortDirection(ref grid1,"GLUSDBR1_deploydate"),
            format: (item) => Html.TextBox("GLUSDBR1", (object)item.GLUSDBT1_deploydate, htmlAttributes: new { @class = "GLUSDBR1TxtBx"}),
            style: "width_deploydates"),

        grid1.Column("GLUSDBP1_deploydate",
            header: "GLUSDBP1 Deploydate " + Html.SortDirection(ref grid1,"GLUSDBP1_deploydate"),
            format: (item) => Html.TextBox("GLUSDBP1", (object)item.GLUSDBT1_deploydate, htmlAttributes: new { @class = "GLUSDBP1TxtBx"}),
            style: "width_deploydates"),
})

SQL过程

对于此过程,Deploydate是参数,它应代表TextBox中任意WebGrid的值。 LogNOInstanceNO只是身份证明。

PROCEDURE p_insert_stmfrd_rel_records(
                                      DeployDate  IN   DATE,
                                      LogNO       IN   NUMBER,
                                      InstanceNO  IN   NUMBER
                                     ) IS
    vNum number;
BEGIN
    select count(1)
    into vNum
    FROM ADM_DEPLOYMENTLOGDETAIL
     WHERE     INSTANCENO = InstanceNO
           AND LOGNO = LogNO
           AND DEPLOYDATE IS NOT NULL;
    IF vNum > 0
    THEN
        BEGIN
            UPDATE ADM_DEPLOYMENTLOGDETAIL
               SET DEPLOYDATE    = DeployDate
             WHERE     INSTANCENO = InstanceNO
                   AND LOGNO = LogNO;
        END;
    ELSE
        BEGIN
            INSERT INTO ADM_DEPLOYMENTLOGDETAIL(
                                                LOGDETAILNO,
                                                DEPLOYDATE,
                                                STATUSID,
                                                CANCELEDIND,
                                                INSTANCENO
                                               )
                 VALUES (
                         ADM_DEPLOYMENTLOGDETAILNO_SQL.NEXTVAL,
                         DeployDate,
                         'D',
                         'N',
                         InstanceNO
                        );
        END;
    END IF;
END p_insert_stmfrd_rel_records;

当前程序调用

public ActionResult SaveChanges(string deployDate)
{
    Convert.ToDateTime(deployDate);
    using (OracleConnection conn = new OracleConnection(Globals.Constants.AppConnectionStringReadOnly))
    {
        OracleCommand objcmd = new OracleCommand();
        objcmd.Connection = conn;
        objcmd.CommandText = "STAMFORDRELEASES.p_insert_stmfrd_rel_records";
        objcmd.CommandType = CommandType.StoredProcedure;
        objcmd.Parameters.Add("DeployDate", OracleDbType.Date).Value = deployDate; // DeployDate
        objcmd.Parameters.Add("LogNO", OracleDbType.Int32).Value = 3; // LogNO / id
        objcmd.Parameters.Add("InstanceNO", OracleDbType.Int32).Value = 3; // InstanceNO / id
        try
        {
            conn.Open();
            objcmd.ExecuteNonQuery();
            OracleDataAdapter da = new OracleDataAdapter(objcmd);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Exception: {0}", ex.ToString());
        }
        conn.Close();
    }
    return null;
}

0 个答案:

没有答案