如何在mvc4中显示详细信息 [英] How Do I Display Details in mvc4

查看:96
本文介绍了如何在mvc4中显示详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC-4的新手..只是一个学习者...当我练习MVC-4时,我有这样做的问题..我有一个控制器 Default1Controller 在那个我有一个显示模型的对象..我的模型代码是这样的..

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..

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; }
       }



和我的Default1Controller代码是这样的......


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);
      }



我的视图(索引)中有一个HTML按钮..所以现在我需要在制作完成后显示这些细节点击按钮...但我无法理解如何为按钮生成Click事件。为什么asp控件没有显示在我的视图中......任何人都可以建议正确的方法来实现这一点..... ..


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.......

推荐答案

以下将显示详细信息:



Following would work to display details :

@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.ActionLink("Detail", "Detail", new { id = Model.Id })


这篇关于如何在mvc4中显示详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆