我有一个模型如下:
public class Class1
{
public int Id { get; set; }
public DateTime Start { get; set; }
}
我有ActionResult
,就像这样:
public ActionResult Create(Class1 model)
{
...
}
现在,我想使用Start
来填充另一个外部javascript
文件中的ajax
属性,如下所示:
$.ajax({
url: "/Admin/Create",
dataType: "Json",
type: "Post",
data: Start:"..."
});
如何访问另一个View
TextBox并使用ajax填充?我应该怎么做关于ajax的数据?
答案 0 :(得分:0)
请尝试以下代码: -
var model = { Name :"Shyju",
Location:"Detroit",
Interests : ["Code","Coffee","Stackoverflow"]
};
$.ajax({
type: "POST",
data: JSON.stringify(model),
url: url,
contentType: "application/json"
}).done(function (res) {
$("#SomeDivToShowTheResult").html(res);
});
public class DashboardViewModel
{
public string Name {set;get;}
public string Location {set;get;}
public List<string> Interests {set;get;}
}
[HttpPost]
public PartialViewResult IndexPartial([FromBody] DashboardViewModel m)
{
return PartialView("_IndexPartial",m);
}
&#13;