Skip to main content

Create Custom View using an Empty Controller in VS 2013: MVC 4

In MVC4 application with Visual Studio 2013, we have added a student controller with its default CRUD actions/views including list, create, edit and details. In this article we will add an empty controller and create a new action with its associated view (having a form in it).

On the controller folder right click and add a new controller. After clicking on Add an Add Controller window will open opting some options shown in the following image:

Create Custom View using an Empty Controller in VS 2013: MVC 4

The first input is the name of controller, write Empty and in the Template option select Empty MVC
Controller and click on “Add”. It will add a new empty controller with a single action i.e. Index having a single line of code, delete this code and create a new action with that single line of code as shown:

public class EmptyController : Controller
public ActionResult GetValues()
return View();
Right click on GetValues text and select Add View option, it will show an Add View window with some of the options to be selected by the programmer. Just select only master file if not selected and leave all remaining options as they are. Those options are not usable now, we will discuss them later.

Create Custom View using an Empty Controller in VS 2013: MVC 4

Click on Add and a view having a piece of code containing title message, layout and a header text also. Leave that code and write the following code in that view:

@using (Html.BeginForm())
        <div>Name: </div>
This code will create a single textbox having the id "username" that will be used to access the value entered in this textbox. There is no button on this form to submit the value of this textbox that will be created in next article. As I have discussed earlier that an action have two types HttpGet and HttpPost. So the above action GetValues is an HttpGet type of method because of single returning view code.

The post method is used to get the inputted values of this view and use them for further process. Through this get method programmer can also send some value to the view just like the title of the view. The title of the view is GetValues as written on the first line of the .cshtml code. Programmer can easily change this title by either sending the title by the Get view or by simple edit this line of code. Now run this MVC application and write http://localhost:portNo/Empty/GetValues in the address bar of the browser and press enter.

Create Custom View using an Empty Controller in VS 2013: MVC 4

Now we will create a submit button on this view and access the value of this textbox in the HttpPost method of the same action in further article.


Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video

Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:

      Suppose next node is allocated at an address 506, so the list becomes,

  Suppose next node is allocated with an address with an address 10,s the list become,

The other way to represent the linked list is as shown below:

 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …