Wednesday, 22 June 2016

How to multiple select list value in mvc without ctrl key?

Multiple select list value in asp.net

Multiple select list value in java script


<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-3.1.1.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-multiselect.css")" rel="stylesheet" />
<script src="@Url.Content("~/Content/MultiCheckbx/js/bootstrap-multiselect.js")"></script>

 <script type="text/javascript">
        $(document).ready(function () {

            $('#ddlLanguage').multiselect({
                includeSelectAllOption: true,
                numberDisplayed: 1,
            });

function Validation() {
    //var language = ListboxChek();
    debugger;
    var languageids = '';
    $('#dvlanguage input[type="checkbox"]:checked').each(function (i, el) {
        languageids += el.value + ',';
        document.getElementById("hdnLanguage").value = languageids;
        var abc = document.getElementById("hdnLanguage").value;
    });
    var abcd = document.getElementById("hdnLanguage").value;
  </script>

When Insert into a table
 @Html.HiddenFor(m => m.hdnLanguage)
 <div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
  @if (Model._listLanguage.Count() > 0)
   {
        foreach (var item in Model._listLanguage)
        {
             <option value="@item.LanguageId"> @item.Name </option>
         }
   }
    </select>
 </div>

  <button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

When Edit after that update
 @Html.HiddenFor(m => m.hdnLanguage)
<div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
    @if (Model._listLanguage.Count() > 0)
       {
           foreach (var item in Model._listLanguage)
           {
               <option value="@item.LanguageId"
                  @if (Model.hdnLanguage != null && (Model.hdnLanguage.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Any(p => (item.LanguageId.ToString().Trim().ToLower() == p.ToString().Trim().ToLower()))))
                                            { <text> selected="selected" </text>  }>
                                                                            @item.Name
                                                                        </option>
             }
        }
    </select>


 </div>
<button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

How to multiple select list value in mvc without ctrl key?

Multiple select list value in asp.net

Multiple select list value in java script


<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-3.1.1.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-multiselect.css")" rel="stylesheet" />
<script src="@Url.Content("~/Content/MultiCheckbx/js/bootstrap-multiselect.js")"></script>

 <script type="text/javascript">
        $(document).ready(function () {

            $('#ddlLanguage').multiselect({
                includeSelectAllOption: true,
                numberDisplayed: 1,
            });

function Validation() {
    //var language = ListboxChek();
    debugger;
    var languageids = '';
    $('#dvlanguage input[type="checkbox"]:checked').each(function (i, el) {
        languageids += el.value + ',';
        document.getElementById("hdnLanguage").value = languageids;
        var abc = document.getElementById("hdnLanguage").value;
    });
    var abcd = document.getElementById("hdnLanguage").value;
  </script>

When Insert into a table
 @Html.HiddenFor(m => m.hdnLanguage)
 <div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
  @if (Model._listLanguage.Count() > 0)
   {
        foreach (var item in Model._listLanguage)
        {
             <option value="@item.LanguageId"> @item.Name </option>
         }
   }
    </select>
 </div>

  <button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

When Edit after that update
 @Html.HiddenFor(m => m.hdnLanguage)
<div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
    @if (Model._listLanguage.Count() > 0)
       {
           foreach (var item in Model._listLanguage)
           {
               <option value="@item.LanguageId"
                  @if (Model.hdnLanguage != null && (Model.hdnLanguage.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Any(p => (item.LanguageId.ToString().Trim().ToLower() == p.ToString().Trim().ToLower()))))
                                            { <text> selected="selected" </text>  }>
                                                                            @item.Name
                                                                        </option>
             }
        }
    </select>


 </div>
<button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

Tuesday, 21 June 2016

How to a file and text value in javascript and sent data in mvc?

<form enctype="multipart/form-data">
    <div class="col-sm-5">
        <div class="form-group">
            <label>Weekend Date:<span id="errorWeekendDate">*</span></label>
            @Html.TextBoxFor(model => model.WeekendDate, new { @Placeholder = "Weekend Date", @required = "required", @style = "height: 35px;border: 1px solid #ccc;border-radius: 4px;" })
            <div class="clearfix"></div>
        </div>
    </div>
    <div class="col-sm-7">
        <a class="file-input-wrapper btn btn-default" style="margin-bottom: 15px;">
            <input type="file" name="file" id="fileInput" data-filename-placement="inside">
        </a>
        <input type="submit" value="Upload file" style="position: relative;top: -5px;" />
    </div>
    <br />
</form>
<div class="clearfix"></div>
<div id="dvmismatch" style="display :none;">
    @Html.Partial("_MismatchVendorList", Model)
</div>



<script type="text/javascript">
    $(function () {
        // When your form is submitted
        $("form").submit(function (e) {
            debugger;
            var errorWeekendDate = document.getElementById('errorWeekendDate');
            var WeekendDate = document.getElementById('WeekendDate');

            if (WeekendDate.value == '') {
                errorWeekendDate.style.color = "red";
                return false;
            }
            else {
                errorWeekendDate.style.color = "";
            }
            e.preventDefault();
            // Serialize your form
            var formData = new FormData($(this)[0]);
            loader();

            // Make your POST
            $.ajax({
                type: 'POST',
                url: '@Url.Action("FileCsv", "InvoiceProcessing")',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    debugger;
                    $("#popup_ok").click();
                    document.getElementById('dvmismatch').style.display = 'block';
                    $("#dvmismatch").html(result);
                },
                error: function (result) { alert(''); }

            });
        });
    })

function loader() {
        debugger;
        jAlert('<img src="@Url.Content("~/Content/images/ajax-loader-large.gif")" height="60" width="60" />', 'Please wait');
        $("#popup_ok").hide();
    }
</script>

        [HttpPost]
        public ActionResult FileCsv(HttpPostedFileBase file, string WeekendDate)
        {
            try
            {
                int result = 0;
                string List = string.Empty;
                DataSet ds = new DataSet();
                if (Request.Files["file"].ContentLength > 0)
                {
                    string fileExtension =
                                        System.IO.Path.GetExtension(Request.Files["file"].FileName);

                    string ImportCSVFile = Request.Files["file"].FileName;
                    string FileName = Request.Files["file"].FileName;
                    string[] strFileName = FileName.Split('.');
                    FileName = strFileName[0];

                    string fileLocation = Server.MapPath("~/Content/CSVFile/") + Request.Files["file"].FileName;
                    if (System.IO.File.Exists(fileLocation))
                    {
                        System.IO.File.Delete(fileLocation);
                    }
                    Request.Files["file"].SaveAs(fileLocation);

                    DataTable dt = new DataTable();

                    string fileName1 = Request.Files["file"].FileName;
                    string path = Path.Combine(Server.MapPath("~/Content/CSVFile/"), fileLocation);

 

                return PartialView("_MismatchVendorList", model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


Sunday, 19 June 2016

How to bind a partial view in a div?

 <div id="dvMappingList" style="display:none;"> </div>

        public ActionResult ServicetoServiceMapping()
        {
            AModel model = new AModel();
            try
            {
             

                return PartialView("_ServiceMapping", model);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

function bindServicetoService(serviceId, IsServiceId) {
        debugger;
        $('#dvMappingList').html('');
        loader();
        $.ajax({
            cache: false,
            type: "GET",
            url: '@Url.Action("ServicetoServiceMapping", "Component")',
            data: { serviceId: serviceId, IsServiceId: IsServiceId },
            success: function (result) {
                debugger;
                $("#dvMappingList").html(result);
                $('.tabclass li').removeClass("active");
                $('#litab3').addClass("active");
                $('.tab-content div').removeClass("in active");
                $('#tab3').addClass("in active");
                //document.getElementById("litab3").style.display = "block";
                document.getElementById("dvMappingList").style.display = "block";
                $("#popup_ok").click();
            },
        }
    )
    };

And after that top to message display and reload the page-:

In Partial view page-

 <div id="prefix_108058000000" class="Metronic-alerts alert alert-success fade in" style="display: none;">
            <a type="button" class="close" data-dismiss="alert" aria-hidden="true"></a>
            <span id="spnmessage1"></span>
        </div>
        <div id="prefix_Error" class="Metronic-alerts alert alert-danger fade in" style="display: none;">
            <a type="button" class="close" data-dismiss="alert" aria-hidden="true"></a>
            <span id="spnmessage2"></span>
        </div>


In Main Page

<div class="page-content" id="dvSubComponat">

In a div tab and partial pages...........

<ul class="nav nav-tabs tabclass">
        <li class="active" id="litab1"><a data-toggle="tab" href="#tab1">A Mapping</a></li>
        <li id="litab2" style="display:none;"><a data-toggle="tab" href="#tab2">Add Edit Employee</a></li>
        <li id="litab3" style="display:none;"><a data-toggle="tab" href="#tab3">DepartmentMapping Mapping</a></li>
        <li id="litab4" style="display:none;"><a data-toggle="tab" href="#tab4">Add Edit Deaprtment Mapping</a></li>
    </ul>

<div class="form-body">
 <div id="tab1" class="tab-pane fade in active">
                                                <div id="dvEmployee">
                                                    @Html.HiddenFor(a => a.EmpID)
                                                    <div class="form-group" style="margin-left:-217px;">
                                                        <label class="control-label col-md-3">
                                                            Search EmployeeID :
                                                        </label>
                                                        <div class="col-md-4">
                                                            @Html.TextBoxFor(m => m.SerTextID, new { @class = "form-control", @onkeypress = "return PopulateEmployeeID();" })
                                                        </div>
                                                    </div>
                                                    <div id="dvserAllList">
                                                        @Html.Partial("_EmployeeAllListPartial", Model)
                                                    </div>
                                                </div>

                                                <div id="dvmaplist" style="display:none;">
                                                    @Html.Partial("_ComponentMappingPartial", Model)
                                                </div>

                                                <div id="dvunmaplist" style="display:none;">
                                                    @Html.Partial("_ComponentUnMappingPartial", Model)
                                                </div>

                                            </div>
</div>

<div id="tab2" class="tab-pane fade">
            @Html.Action("AddEditEmployee", "Component", new { ID = 0 })
        </div>
</div>

 function SuccessSubComponent(data) {
        $("#popup_ok").click();
        if (data != null) {
            debugger;
            if (data.indexOf("exist") != -1) {
                $('#prefix_Error').show();
                $('#prefix_Error').removeClass("fade");
                $("#spnmessage2").html(data);
                $("#spnmessage2").focus();
                $('html,body').animate({
                    scrollTop: $("#dvSubComponat").offset().top
                },
       'slow');
                setTimeout("loadSubComponentReload()", 1000);
            }
            else {
                debugger;
                $('#prefix_108058000000').show();
                $('#prefix_108058000000').removeClass("fade");
                $("#spnmessage1").html(data);
                $("#spnmessage1").focus();
                $('html,body').animate({
                    scrollTop: $("#dvSubComponat").offset().top
                },
       'slow');
                setTimeout("loadComponentMapReload()", 1000);
            }
        }
    }

    function loadComponentMapReload() {
        window.location.href = "@Url.Action("ComponentMapping", "Component")";
    }


Wednesday, 15 June 2016

How to display some character in mvc?

@(model.ShortDescription.Length > 130 ? model.ShortDescription.Substring(0, 131)+"..." : model.ShortDescription)

Wednesday, 1 June 2016

How to multiple parameter pass in window.location in mvc?

window.location.href = "/Controller/Action?id=" + historyId + "&check=" + itemfilter;

How to split the string in asp.net?

   if (!string.IsNullOrWhiteSpace(tempitemnoList))
                    {
                        string[] tempNumber = tempitemnoList.Split(new string[] { "/" }, StringSplitOptions.None);
                        if (tempNumber.Count() > 0)
                        {
                            for (int i = 0; i < tempNumber.Count(); i++)
                            {
                                if (tempNumber[i] != "")
                                {
                                    string[] temp = tempNumber[i].Split(new string[] { "," }, StringSplitOptions.None);
                                    if (temp.Count() > 0)
                                    {
                                        if (temp[0] != "")
                                        {
                                            string VendorItemNo = temp[0];
                                            VendorItem item = new VendorItem();
                                            var data = objdb.GetInvoiceImportPriceById(Convert.ToInt32(temp[0])).FirstOrDefault();
                                            if (data != null)
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return Json(new { success = true }, JsonRequestBehavior.AllowGet);