Monday, 18 February 2013

Dropdownlist in MVC ASP.Net

Dropdownlist in MVC ASP.Net

As per requirement we will develop application .We build simple MVC application based on DropDownlist


Controller Section :


       public ActionResult Index()
        {

            ViewData["ques"] = new SelectList(_testEntities.ques, "qno","question");
            return View();
        }


Add View , to inherit database entities.

View Section





<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Index</h2>
   
    <% using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
       {%>
       
         <div class="display-label">Questions</div>
        <%= Html.DropDownList("Questions", (SelectList)ViewData["ques"], "---select One----", new {  onchange = "this.form.submit();" }) %>
     
       <% } %>

         
</asp:Content>










Friday, 15 February 2013

Difference between ViewResult and ActionResult


 ViewResult and ActionResult



       ActionResult is an abstract class that can have several subtypes.
       ViewResult - Renders a specifed view to the response stream

c# code for :
       public ViewResult Result()        {
            SHIFT_MAST _shift = new SHIFT_MAST();
            _shift.shift_cd = "1";
            _shift.shift_id = 2;
            _shift.start_time = "8.30";
            return View("Result", _shift);
        }

        public ActionResult ResultAction()
        {
            SHIFT_MAST _shift = new SHIFT_MAST();
            _shift.shift_cd = "1";
            _shift.shift_id = 2;
            _shift.start_time = "8.30";
            return View("ResultAction", _shift);
        }

ActionResult is an abstract class and its base class for ViewResult class
In MVC , it uses ActionResult class to reference the object your action method returns and invokes ExecuteResult method on it.
And ViewResult is an implementation for this abstract class. It will try to find a view page (usually aspx page) in some predefined paths(/views/controllername/, /views/shared/, etc) by the given view name.


Wednesday, 6 February 2013

Adding serial number for rows in SQL Server

Adding serial number based on number of rows displaying.

You need to add following to your query or Column Name

Syntax :


Row_Number() Over (Order By a.emp_mast_id) As emp_mast_id

Example  :


select Row_Number() Over (Order By a.emp_mast_id) As emp_mast_id,
a.emp_name,
a.address
from Emp_mast a


ID   Name   Address
1     Nihar    India
2     sam       UK
3     John      USA