需要根据jQueryHTTP(Ajax)请求访问模型
当我执行http ajax请求时,我想使用表单中的数据访问模型。我不确定这是否可行,因此我可能需要在请求中包含所需的数据 从视图中,我有一个jquery.ajax调用需要根据jQueryHTTP(Ajax)请求访问模型,jquery,asp.net-mvc,Jquery,Asp.net Mvc,当我执行http ajax请求时,我想使用表单中的数据访问模型。我不确定这是否可行,因此我可能需要在请求中包含所需的数据 从视图中,我有一个jquery.ajax调用 $.ajax({ url: this.href, cache: false, success: function (html) { $("#editorPriceRows").append(html); } }); 在我的控制器里,我有这个动作 public ActionResult NewDateRow(My
$.ajax({
url: this.href,
cache: false,
success: function (html) { $("#editorPriceRows").append(html); }
});
在我的控制器里,我有这个动作
public ActionResult NewDateRow(MyModel model)
{
// here I want to check some of the values i filled out in my form but have not posted yet and depending on this value, I will set some data in the model I am passing to the partial view.
return PartialView("_DateEditRow", partialModel);
}
我需要检查表单中的日期,以查看需要在传递给partialview的模型中设置哪些数据。这可能吗?您不能直接从jQuery访问您的模型,但可以尝试以下操作:
var model = @Html.Raw(Json.Encode(Model));
然后,您必须将数据传递给控制器操作(缓存:false,数据:…,)。是的,您可以使用
@Ajax.actionlink
例:
这将起作用,但由于这个ajax调用,一旦执行它,您可能就看不到它的源代码
$ajaxrequest(..)
您可以检查语法
您仍然可以使用jquery
谢谢是的,我对上面代码的问题是模型总是空的。
@Ajax.ActionLink("Any friedly name", "YourAction", new { uaid = Model.xyzclass.Parametername}, new AjaxOptions { UpdateTargetId = "whateverurplacholder forholdingmsg",OnSuccess = "xyz", OnFailure = "xyz" } })