Wednesday, 7 November 2018

Making Admin Panel in Online Quiz Application Asp.net MVC C#








Click here to download the source code

Loading Progress Bar in asp.net mvc using ajax,jquery and Bootstrap Modal





@model WebApplication28.Models.tbl_employee

@{

    ViewBag.Title = "Home Page";

}



<script src="~/Scripts/jquery-1.10.2.min.js"></script>

<link href="~/Content/bootstrap.min.css" rel="stylesheet" />

<script src="~/Scripts/bootstrap.min.js"></script>



<style>

    td{

        padding:10px;

    }

</style>

<div class="container">

    <br />

    <a href="#" class="btn btn-block btn-success" data-toggle="modal" data-target="#myModal">Add a new Record</a>



    <div class="modal fade" id="myModal">

        <div class="modal-dialog">

            <div class="modal-content">



                <div class="modal-header">

                    <a href="#" class="close" data-dismiss="modal">&times;</a>

                    <h3 class="modal-title">Add a new Record! </h3>



                </div>



                <div class="modal-body">



                    <form id="myForm">



                        <table >

                            <tr>

                                <td>Name: </td>

                                <td>@Html.TextBoxFor(x => x.emp_name, new {@class="form-control" }) </td>

                            </tr>



                            <tr>

                                <td>Contact: </td>

                                <td>@Html.TextBoxFor(x => x.emp_contact, new { @class = "form-control" }) </td>

                            </tr>





                        </table>







                        </form>



                    <div style="text-align:center;display:none" id="loaderDiv">

                        <img src="~/Content/img/tenor.gif" />



                    </div>



                    </div>









                <div class="modal-footer">



                    <a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>

                    <input type="reset" value="Submit" class="btn btn-success" id="btnSubmit" />



                </div>



            </div>



        </div>

    </div>

</div>







<script>



    $(document).ready(function () {





        $("#btnSubmit").click(function () {



            $("#loaderDiv").show();



            var myformdata = $("#myForm").serialize();



            $.ajax({



                type: "POST",

                url: "/Home/Index",

                data: myformdata,

                success: function ()

                {

                    $("#loaderDiv").hide();

                    $("#myModal").modal("hide");



                }



            })

        })



    })





</script>

Monday, 5 November 2018

Quiz application in asp net mvc part 1







Download the source code

Ajax with MVC (Insert data using ajax in asp.net mvc)







<script src="~/Scripts/jquery-1.10.2.min.js"></script>



<script>



    $(document).ready(function () {



        $("#btnSubmit").click(function () {



            $("#loaderDiv").show();



            var data = $("#myForm").serialize();



            $.ajax({



                type: "POST",

                url: "/Home/Index",

                data: data,

                success: function (response) {

                    $("#loaderDiv").hide();

                    alert("Question Successfully inserted......");

                }



            })

        })





    })





</script>


Wednesday, 24 October 2018

Upload and Save Image in database , asp net mvc 5



public string uploadimage(HttpPostedFileBase file)

        {

            Random r = new Random();

            string path = "-1";

            int random = r.Next();

            if (file != null && file.ContentLength > 0)

            {

                string extension = Path.GetExtension(file.FileName);

                if (extension.ToLower().Equals(".jpg") || extension.ToLower().Equals(".jpeg") || extension.ToLower().Equals(".png"))

                {

                    try

                    {



                        path = Path.Combine(Server.MapPath("~/Content/upload"), random + Path.GetFileName(file.FileName));

                        file.SaveAs(path);

                        path = "~/Content/upload/" + random + Path.GetFileName(file.FileName);



                        //    ViewBag.Message = "File uploaded successfully";

                    }

                    catch (Exception ex)

                    {

                        path = "-1";

                    }

                }

                else

                {

                    Response.Write("<script>alert('Only jpg ,jpeg or png formats are acceptable....'); </script>");

                }

            }



            else

            {

                Response.Write("<script>alert('Please select a file'); </script>");

                path = "-1";

            }







            return path;

        }


Friday, 19 October 2018

Pagination in asp net mvc





Action code:



public ActionResult Index(int? page)

        {

            int pagesize = 6, pageindex = 1;

            pageindex = page.HasValue ? Convert.ToInt32(page) : 1;

            var list = db.tbl_services.OrderByDescending(x => x.s_id).ToList();

            IPagedList<tbl_services> stu = list.ToPagedList(pageindex, pagesize);



            return View(stu);

        }

View code:

@using PagedList.Mvc

@model  PagedList.IPagedList<WebApplication1.Models.tbl_services>







@{

    ViewBag.Title = "Home Page";

}



<div class="row">



    @foreach (var item in Model)

    {

        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">

            <img  src="@Url.Content(item.s_img)" style="width:200px; height:200px;"/>

            <h1 style="text-align:center"> @item.s_name</h1>



        </div>



    }

   





</div>

   

    <div>



        <div class="pagination" style="margin-left: 400px">

            Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)

            of @Model.PageCount   @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))

        </div>







    </div>


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...