【问题标题】:MVC razor update record inside jquery dialogjQuery对话框中的MVC剃须刀更新记录
【发布时间】:2013-12-20 12:47:10
【问题描述】:

我有一个 mvc razor 视图,这个视图包含几条记录。现在我如何在 jquery 对话框中获取记录以进行更新。我没有根据“Route ID”获取记录,因为它是 5 并且没有该 ID 的数据5.我应该将它用于ajax还是我可以不使用ajax来解决这个问题?

页面详情如下。

EmployeeDetail.cshtml

网址:EmployeeDetail/5

@model EmployeeCvBank.EmployeeRepository

人物:伊拉克利·祖拉泽

部门:IT / 软件开发人员

                                                           + Add new education
+------+--------------------------------+----------------+-------------------+
|  ID  |  Education                     |  Graduate      |  Actions          |
+------+--------------------------------+----------------+-------------------+
|  1   |  Batumi University Msc         |  1/7/2012      |  Edit / Delete    |
+------+--------------------------------+----------------+-------------------+
|  2   |  Tbilisi State University Ms   |  25/9/2010     |  Edit / Delete    |
+------+--------------------------------+----------------+-------------------+

教育知识的编辑和删除操作

public ActionResult EditEducation(PersonEducation model)
{
    ...
}

public ActionResult DeleteEducation(int id)
{
    ...
}

public class EmployeeRepository
{
    public Employee Employee {get;set;}
    public Education Education {get;set;}
}

【问题讨论】:

  • 记录 id 5 是什么意思?

标签: asp.net-mvc jquery-ui razor jquery-ui-dialog


【解决方案1】:

如果我没记错的话,您想修改 ID 为 5 的用户的教育详细信息吗?

总有办法解决

步骤

  1. 创建隐藏字段,它将在表单提交时保存您的教育 ID。

    @Html.Hidden("EducationId")
    
  2. 将 onclick 事件添加到“编辑”链接

    <a href="javascript:PopulateHiddenFieldsBeforeSubmit('@education.id')" >Edit</a>
    <script>
      function PopulateHiddenFieldsBeforeSubmit(educationId)
       {
         $("#EducationId").val(educationId);//prove hidden educationid field with selected value
         document.forms[0].submit();
       }
    

  3. 装饰员工帖子操作

    Public ActionResult EmployeeDetail(EmployeeRepository collection, int EducationId)
    {
      //Now you have desired educationid here
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2016-07-23
    • 1970-01-01
    相关资源
    最近更新 更多