Ajax actionLink onSuccess获取html格式的数据

时间:2018-01-31 09:32:42

标签: javascript ajax asp.net-mvc

我有一个Ajax助手类,它调用控制器,控制器又使用模型数据返回PartialViewResult,PartialViewResult呈现IEnumerable。我想从PartialViewResult返回的模型中获取一个ID,我不知道该怎么做,我甚至使用了TempData但它没有用,所以AjaxLink有{{1}获取数据然后数据是html格式的方法所以我需要一些从模型中获取ID并将其分配给OnSucesss的东西(请查看父视图的最后一条语句)

控制器

Actionlink

ParentView

public ActionResult GetContacts(string q, int limit = 5, int p = 1, int per_page = 5)
{

    return PartialView("DateRange2_Partial", Model);
}

PartialView

<div class="col-xs-6" id="DepartmentDetails">                                                 
    @Html.Partial("DateRange2_Partial",Model)
</div>
@Ajax.ActionLink("click me",
    "GetContacts",
    "Home",
    new AjaxOptions
    {
        UpdateTargetId = "DepartmentDetails",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET",
        OnSuccess = "OnAjaxRequestSuccess"
    }
)



<script type="text/javascript">
    function OnAjaxRequestSuccess(data) {
        // Get value from data and pass it to the Action link?
    }
<script/>

@Html.ActionLink("Redirect", "Action", new { SingleDatePicker = ***Assign value here from Ajax action link***})

0 个答案:

没有答案