【问题标题】:Html.ActionLink to happen in different part of codeHtml.ActionLink 发生在代码的不同部分
【发布时间】:2017-05-21 15:37:31
【问题描述】:

我正在尝试制作 ActionLink,这将在另一部分代码中发生,例如:

  <div class="col-md-4">
                @Html.ActionLink(some button to click and perform "Action"   div)
            </div>

  <div id="Action>
      <div class="col-md-12">
                @Html.Action(some action to be done)
      </div>
  </div>

所以我想知道是否可以将参数发送到“Action”,因为我想调用视图

【问题讨论】:

  • - ActionLink 只会生成一个指向另一个页面的链接 (你可以指定一些参数) - Action 方法用于调用一个控制器,它将在你的视图中呈现 html :stackoverflow.com/questions/3150491/…

标签: html asp.net


【解决方案1】:

试试这样的:

@Html.ActionLink("Edit", "Edit", new { id = item.EmployeeID })

动作如下所示:

public ActionResult Edit(int id)
{
//action code

}

【讨论】:

    【解决方案2】:

    这应该可以工作

    <div class="col-md-4">
         <a href="@Url.Action("TestAction", "Test", new {parameterName= "parameterValue"})">
    </div> 
    

    确保你的锚标记中的parameterName与TestController中TestAction中的parameterName相同

    public class TestController : Controller
    {
        public ActionResult TestAction(int parameterName)
        {
            // Do something...
    
            return View();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多