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

Monday, 23 May 2016

How to more than one list value to add another list value in MVC?

 *************Employee Model*******************
 public classEmployeeModel
    {
        public EmployeeModel()
        {
            EmployeeList = new List<EmployeeModel>();
            StudentList = new List<EmployeeModel>();

            ServiceList = new List<SelectListItem>();
            ParentList = new List<SelectListItem>();
            GenderList= new List<SelectListItem>
            {
               new SelectListItem() {Text = "--Select--", Value ="0" },
               new SelectListItem() {Text = "Male", Value ="1" },
               new SelectListItem() {Text = "Female", Value ="2"},
             };
        }
        public int ID { get; set; }
        public string Name{ get; set; }
        public string Address{ get; set; }
        public int Age{ get; set; }
        public string Mobile{ get; set; }
     
        public List<EmployeeModel> EmployeeList { get; set; }
        public List<EmployeeModel> StudentList { get; set; }
        public IEnumerable<Employee> SerList { get; set; }

        public decimal? ServiceUsage { get; set; }
        public decimal? ServiceCost_Per_Annum { get; set; }
        public decimal? ServiceCost_for_Service { get; set; }

        public List<SelectListItem> GenderList{ get; set; }

    }

************************End Employee Model**************************
var empList = _apiService.GetAllEmployee().ToList();
                    model.EmployeeList = stcList.Select(x =>
                    {
                        return new EmployeeModel()
                        {
                            ID = x.ID == null ? 0 : x.ID.Value,
                            Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
                            Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
                            Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
                            Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
                        };
                    }).ToList();

                    var stuList = _apiService.GetAllStudent().ToList();
                    model.StudentList = stuList .Select(x =>
                        {
                            return new ComponentModel()
                            {
                               ID = x.ID == null ? 0 : x.ID.Value,
                            Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
                            Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
                            Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
                            Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
                            };
                        }).ToList();


var AddExData = new List<EmployeeModel>();

AddExData.AddRange(model.EmployeeList);
AddExData.AddRange(model.StudentList);

Sunday, 1 May 2016

How to windows authentication in mvc?

Firstly, in web.config to configure-:

<system.web>  
    <authentication mode="Windows"></authentication>
    <authorization>
      <deny users="?" />
    </authorization>
 </system.web>

After that Project property (F4 Click)
Windows Authentication Diable and Autonymous Authentication Enabled.

After that it works.
  string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            string IsAuthentication = System.Web.HttpContext.Current.Request.IsAuthenticated.ToString();
            string[] paramsLogin = domainUser.Split('\\');
            string UserName = paramsLogin[1].ToString();

How to log out windows authentication in mvc?

public ActionResult LogOut()
{
    HttpCookie cookie = Request.Cookies["TSWA-Last-User"];

    if(User.Identity.IsAuthenticated == false || cookie == null || StringComparer.OrdinalIgnoreCase.Equals(User.Identity.Name, cookie.Value))
    {
        string name = string.Empty;

        if(Request.IsAuthenticated)
        {
            name = User.Identity.Name;
        }

        cookie = new HttpCookie("TSWA-Last-User", name);
        Response.Cookies.Set(cookie);

        Response.AppendHeader("Connection", "close");
        Response.StatusCode = 401; // Unauthorized;
        Response.Clear();
        //should probably do a redirect here to the unauthorized/failed login page
        //if you know how to do this, please tap it on the comments below
        Response.Write("Unauthorized. Reload the page to try again...");
        Response.End();

        return RedirectToAction("Index");
    }

    cookie = new HttpCookie("TSWA-Last-User", string.Empty)
    {
        Expires = DateTime.Now.AddYears(-5)
    };

    Response.Cookies.Set(cookie);

    return RedirectToAction("Index");

}