用户单击“提交”按钮时获取记录 [英] Get Records when user Click on Submit button

查看:57
本文介绍了用户单击“提交”按钮时获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个下拉列表。当我选择品牌下拉列表时。它填写产品下拉列表中的记录,并显示基于品牌的销售记录。但我希望只有当用户点击提交按钮时才能填写销售记录。





查看:



I have 3 dropdown list. when i select brand dropdownlist. it fill the records in Product dropdownlist as well it display sales records based on Brand. but i want sale records should fill only when user click on Submit button.


View :

@model withoutModelEdmx.Models.masterList

@{
    ViewBag.Title = "dropdownlist bind demo with model";  
}
@using (Html.BeginForm("postyourad", "stok", FormMethod.Post, new { id = "TheForm" }))
 {
    @Html.DropDownListFor(x => x._brand, Model.getBrand(), "--Choose Your Brand--",
    new
    {
        onchange = "document.getElementById('TheForm').submit();"
    })
    @Html.DropDownListFor(x => x._product, Model.getProduct(), "--Choose Your Product--",
    new
    {
        onchange = "document.getElementById('TheForm').submit();"
    })
    @Html.DropDownListFor(x => x._model, Model.getModel(), "--Choose Your Model--",
    new
    {
       onchange = "document.getElementById('TheForm').submit();"
    }    )
       
   <input type="submit" value="submit"  />
   
    @foreach (var list in Model.GetSaleRecords())
    { 
        
    }
     
            
              @list.Id
                      
            <input value="@list.bill_amt" type="text" class="data1" />
            
            @list.brand
            
            @list.product
            
            <input value="@list.price" type="text" class="data1" />
            
            @list.Qty
            
          
 }







控制器:




Contoller:

[HttpGet]
    public ActionResult postyourad()
    {
        return View(new masterList());
    }
    [HttpPost]
    public ActionResult postyourad(masterList ddlListPostData)
    {
        return View(ddlListPostData);
    }







型号:




Model:

public class masterList
    {

        [Required]
        public virtual string _model { get; set; }
        [Required]
        public virtual string _product { get; set; }
        [Required]
        public virtual string _brand { get; set; }

        public IList<SelectListItem> mastr_name { get; set; }
        ConnectionClass con_cs = new ConnectionClass();
        public SelectList getBrand()
        {
            IEnumerable<SelectListItem> BrandList = (from s in con_cs.stock_entries                                                   
                                                     select new SelectListItem()
                                                     {
                                                         Text = s.brand,
                                                         Value = s.brand
                                                     }).Distinct().OrderBy(x => x).ToList<SelectListItem>();
            return new SelectList(BrandList, "Value", "Text", _brand);
        }
        public SelectList getProduct()
        {
            IEnumerable<SelectListItem> ProductList = new List<SelectListItem>();
            if (!string.IsNullOrEmpty(_brand))
            {
                ProductList = (from s in con_cs.stock_entries
                               where s.brand == _brand
                               select new SelectListItem()
                               {
                                   Text = s.product,
                                   Value = s.product
                               }).Distinct().ToList<SelectListItem>();
            }
            return new SelectList(ProductList, "Value", "Text", _product);
        }        
        public SelectList getModel()
        {
            IEnumerable<SelectListItem> ModelList = new List<SelectListItem>();
            if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product))
            {
                ModelList = (from s in con_cs.stock_entries
                             orderby s.model
                             where s.brand == _brand && s.product== _product
                             select new SelectListItem()
                             {
                                 Text = s.model,
                                 Value = s.model
                             }).Distinct().ToList<SelectListItem>();
            }
            return new SelectList(ModelList, "Value", "Text", _model);
        }
        public List GetSaleRecords()
        {
            List query = new List();          
            if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product) && !string.IsNullOrEmpty(_model))            
            {

                query = (from pd in con_cs.SaleDtls_entries
                         join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                         where pd.brand == _brand && pd.product == _product && pd.model_no == _model
                         orderby od.Id
                         select new Mydata
                         {
                             Id = od.Id,
                             req_no = od.req_no,
                             product = pd.product,
                             brand = pd.brand,
                             price = pd.price,
                             Qty = pd.Qty,
                             bill_amt = od.bill_amt,
                         }).ToList();
            }
            else
            {
                if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product))
                {
                    query = (from pd in con_cs.SaleDtls_entries
                             join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                             where pd.brand == _brand && pd.product == _product
                             orderby od.Id
                             select new Mydata
                             {
                                 Id = od.Id,
                                 req_no = od.req_no,
                                 product = pd.product,
                                 brand = pd.brand,
                                 price = pd.price,
                                 Qty = pd.Qty,
                                 bill_amt = od.bill_amt,
                             }).ToList();
                }
                else
                {
                    if (!string.IsNullOrEmpty(_brand))
                    {
                        query = (from pd in con_cs.SaleDtls_entries
                                 join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                                 where pd.brand == _brand
                                 orderby od.Id
                                 select new Mydata
                                 {
                                     Id = od.Id,
                                     req_no = od.req_no,
                                     product = pd.product,
                                     brand = pd.brand,
                                     price = pd.price,
                                     Qty = pd.Qty,
                                     bill_amt = od.bill_amt,
                                 }).ToList();
                    }
                }
            }
            return query;
        }
    }

推荐答案

现在每3个下拉列表中都会自动关联OnClick事件提交表单(模拟按下提交按钮)。所以你必须改变这些java脚本代码,你可以使用jQuery和AJAX来只填充下拉列表,而不是提交整个页面。
Now for each 3 drop down list there is"OnClick" event associated that automatically submit your form (simulating press on submit button). So you have to change these java script code and you could for example use jQuery and AJAX to fill only the drop down list and not to submit the entire page.


这篇关于用户单击“提交”按钮时获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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