【问题标题】:How to get parameter from url action如何从 url 动作中获取参数
【发布时间】:2013-10-16 02:31:31
【问题描述】:

我有这个方法:

 public ActionResult Edit(string Id) {

        return PartialView("Edit",Id);
    }

和我的视图:

<a class="openEditdialog" onclick="javascript:OpenWindow('@Url.Action("Edit", "RegisterBrand", new { Id = @item.Id})')" ></a>

但是,我不知道为什么 Edit() 中的 Id 变量为空????

【问题讨论】:

  • 不应该是new { Id = @item.Id})new { Id = @Model})
  • 您的@Url.Action 实际呈现的网址是什么?
  • @Chandu item 是 Model 的实例。
  • @David 我不知道为什么参数 item.Id 在我尝试时也为空 一切正常。

标签: asp.net-mvc-3 url-action


【解决方案1】:

试试这个我希望这会有所帮助..

考虑中

<a href="@Url.Action("Edit", "Home", new { Id = @item.ID})">TestLink</a> 

在你的 Home 控制器中

 public ActionResult Edit(int id)
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

【讨论】:

    【解决方案2】:

    返回局部视图并指定模型时,即

    return PartialView("Edit",Id);
    

    Id 是一个字符串,那么在您的局部视图中对Model 的引用将是一个字符串,您的代码表明存在一些带有.Id 属性的神奇对象它。您的视图将使用 @Model 来获取字符串。例如

    <a href="@Url.Action("Edit", "RegisterBrand", new { Id = @Model })">link text</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      相关资源
      最近更新 更多