Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to MVC-4 ..just a learner...when i practicing MVC-4, I have a problem of doing this..ie i have a Controller Default1Controller in that i have an object of Display Model.. my model code is like this..
C#
public class Display
   {
       private string  name;

       public string Name
       {
           get { return name; }
           set { name = value; }
       }
       private int age;

       public int Age
       {
           get { return age; }
           set { age = value; }
       }
       private string adress;

       public string Adress
       {
           get { return adress; }
           set { adress = value; }
       }

and my Default1Controller code is like this...
public ActionResult Index()
      {
          Display di = new Display();
          di.Name = "Kumar";
          di.Age = 12;
          di.Adress = "Nellore";

          return View(di);
      }

and i have an HTML button in my View(Index)..so now i need to display these details after when i made a click to button...but i can't understand how to generate Click event for button..why asp controls are not displaying in my view...could any one please suggest the right way to achieve this.......
Posted
Updated 14-Jul-14 21:12pm
v2

1 solution

Following would work to display details :

HTML
@model Namespace.Models.Display

<h2>Details</h2>

<div>

    <div>
         @Html.DisplayNameFor(model => model.Name) : @Html.DisplayFor(model => model.Name)
    </div>

    <div>
         @Html.DisplayNameFor(model => model.Age) : @Html.DisplayFor(model => model.Age)
    </div>

    <div>
         @Html.DisplayNameFor(model => model.Adress) : @Html.DisplayFor(model => model.Adress)
    </div>
        
</div>


And for click event you just need to provide anchor tag like following :

HTML
@Html.ActionLink("Detail", "Detail", new { id = Model.Id })
 
Share this answer
 
v2
Comments
Naveen Kumar Malli 15-Jul-14 3:59am    
S...its working ThanQ..so much sasolanki...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900