Controller public JsonResult FillRoles() { return Json(BLLFile.FillUserRoles(), JsonRequestBehavior.AllowGet); } Code in BLL file public static List<sp_FillUserRoles_Result> FillUserRoles() { using (Db_obj db = new Db_obj()) { return db.sp_FillUserRoles().ToList(); } } Explanation Now, Understand the sequence: View will ask controller to send data.FillRoles() Method in controller will request data from BLL file so it will give call... Continue Reading →
Populate dropdown list based on data retrieved from database in MVC Application (VIEW)
View jquery function getRelation() { $.ajax ({ url: "@(Url.Action("FillRoles", "Roles"))", data: {}, success: function (result) { var html = ""; html += "<option>Select</option>"; for (var i = 0; i < result.length; i++) { html += "<option value=" + result[i].ID + ">" + result[i].Description + "</option>"; } $("#ddlAddRoles").html(html); } }); } html <div class="col-sm-4 tb-font"> <form>... Continue Reading →
Pass data from view to controller in JSON format- MVC Application
View jquery function Save() { $.ajax ({ url: "@(Url.Action("SaveMember", "Members"))", data: { name: $("#MemberName").val(),designation: $("#ddlDesignation option:selected").val() }, contentType: "application/json; charset=utf-8", type: 'GET', dataType: "json", success: function (result) { alert("Record saved successfully."); }, error: function () { alert("Something went wrong, please try again"); } }); } html <div class="col-sm-4 tb-font"> @Html.Label("name", "Member Name", new { style... Continue Reading →
Print.js- A tiny JavaScript library
Button to Print as PDF <button type="button" onclick="printJS('docs/printjs.pdf')"> Print PDF </button> Button To print large PDF files <button type="button" onclick="printJS({printable:'docs/xx_large_printjs.pdf', type:'pdf', showModal:true})"> Print PDF with Message </button> Button to Print base64 PDF <button type="button" onclick="printJS({printable: base64, type: 'pdf', base64: true})"> Print PDF with Message </button>
Uplaod File HTML
HTML <form action="#"> <label class="col-form-label">Display Picture <span class="text-danger">*</span></label> <input type="file" id="Picfile" name="pic" class="form-control"> </form> Explanation This will allow user to upload file as the input type is file.
Select data from multiple tables and use aliases
code SELECT p.*, c.ID, c.Description as CategoryName FROM Products p, Categories c where p.CategoryID=c.ID Explanation This will select everything from products table and only 'ID' and 'Description' from categories table given the category IDs are same. Note that the alias for 'Products' table is p and Alias for 'Categories' table is c. Column 'Description' of... Continue Reading →
SQL Update
Code UPDATE Math_Results SET Marks=80 WHERE marks=79; EXPLANATION This update query will update the table Math_Results and set the marks of all students to 80 who secured 79 marks.
USE of COALESCE in a Stored Procedure MySQL
use of coalesce USE [DB_Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_FillMarks] @studentId bigint AS BEGIN SET NOCOUNT ON; SELECT ID, Name, Marks FROM t_Results r where STUDENTID = COALESCE(NULLIF(@studentId, '0'), STUDENTID) and Marks >= 80 END Explanation This will select details of student whose id is passed to the... Continue Reading →
Dropdown not getting bind using .val() and giving value in alert as null.
Nooper posted this problem and since we are not familiar with the context in which she is facing the problem we can give generic solutions to what we understand from the problem description: If you want to show the selected value in alert box, you can do it like this: alert($("#ddlGender option:selected").val()); This will show... Continue Reading →
SQL Aliasing
SQL Aliases SQL aliases are actually temporary names given to tables or a column or columns in a table. They do not actually create a new column in the database, but are the temporary readable names given to columns or tables for the time of the execution of the query. So, they only exists for... Continue Reading →