简体   繁体   English

在C#/ html上使用实体框架时,如何将多个参数传递给Actionlink()

[英]How can I pass multiple parameters to Actionlink() while working with entity framework on c#/html

In my project i am working with MVC design and using the database with Entity Framework. 在我的项目中,我正在使用MVC设计,并将数据库与Entity Framework一起使用。 I wanted to update some cells in my database, but I am not sure how to pass them to the controller to update. 我想更新数据库中的某些单元,但是我不确定如何将它们传递给控制器​​进行更新。

On the Update View page, the user can change the content of the cells using 在“更新视图”页面上,用户可以使用以下命令更改单元格的内容

 <td> <div contenteditable> @Html.DisplayFor(Model => Model.HeadLine) </td> 

But when I try to send the updated data to the controller I can only understand how to send an id for the Model(because I cannot pass the Model itself). 但是,当我尝试将更新的数据发送到控制器时,我只能理解如何为模型发送ID(因为我无法传递模型本身)。

I am not sure what I am doing wrong - here I am trying to pass an ID so the controller would know what to change and the new name - I get a compilation error. 我不确定自己在做什么错-我在这里尝试传递一个ID,以便控制器知道要更改的内容和新名称-我收到编译错误。

 <p> @Html.Action("Update This Post >>", "Update", new { param1 = Model.ID, param2 = Model.Author }); </p> 

The controller signature is : 控制器签名为:

  [HttpPost] public ActionResult Update(int id, string author) 

Try this : 尝试这个 :

<p>
    @Html.ActionLink("Update This Post >>","YourController", "Update", new { id = Model.ID, author = Model.Author });
</p>

I am not sure whether you are trying to pass a reference type or value type variables in the action. 我不确定您是否要在操作中传递引用类型或值类型变量。 you should not pass the reference type but the value types for the anonymous object to pass route parameters. 您不应传递引用类型,而应传递匿名对象的值类型以传递路由参数。 Can you try the below code 你可以尝试下面的代码吗

@Html.ActionLink("Update This Post >>", "Update", new { id= Model.ID, author= Model.Author });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#ActionLink MVC4-将多个参数传递给ActionResult - C# ActionLink MVC4 - Pass multiple parameters to ActionResult 如何将两个参数从ActionLink传递到ActionResult - How can I pass two parameters from ActionLink to ActionResult 如何创建包含图标的C#MVC HTML ActionLink? - How can I create a C# MVC Html ActionLink that contains an icon? C#如何将实体框架实体与ObservableCollection一起使用 - C# How can i use Entity Framework Entities with ObservableCollection 使用@ Html.ActionLink将多个参数传递给控制器 - Using @Html.ActionLink to pass multiple parameters to controller 如何在C#中将值从Entity传递到Presentation - How can I pass values from Entity to Presentation in c# C# 实体框架 - 如何在 Where 子句中动态传递值 - C# Entity Framework - How to pass a value in the Where clause dynamically 如何使用实体框架在具有多个连接的查询中使用可选参数? - How can I use optional parameters in a query with multiple joins, using Entity Framework? 我可以在Entity Framework 5,c#中的两个实体之间创建多个关联吗? - Can I create multiple associations between two entities in Entity Framework 5, c#? Html.ActionLink()不适用于传递C#对象 - Html.ActionLink() not working for passing a C# object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM