ASP.NET Core MVC를 배우고 있습니다. 나는이 모델이 있습니다Asp.net 핵심 단추 데이터 바인딩
public class Todo
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[MaxLength(4096)]
public string Content { get; set; }
public bool isCompleted { get; set; } = false;
public DateTime DateCreated { get; set; } = DateTime.UtcNow;
public string UserName { get; set; }
}
을 내가 같은 버튼에 isCompleted
을 바인딩 할 : 그 버튼을 클릭하면, 그 값이 변경 될 것입니다. 현재 내가 Ajax를 사용하고 있습니다 :
CompleteTodo = function (id, isCompleted) {
if (isCompleted === true) {
var data = "{\n \"isCompleted\": false,\n}"
} else {
var data = "{\n \"isCompleted\": true,\n}"
}
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:3000/api/todos/"+id,
"method": "PUT",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache",
},
"data": data
}
$.ajax(settings).done(function (response) {
console.log(response);
});
}
문제는, 내가 호출 후 버튼의 클래스를 변경할 수 없습니다, 내 버튼 태그 :
<button id="ButtonComplete" href="#" onclick='CompleteTodo(@item.Id,@item.isCompleted.ToString().ToLower())' class="waves-effect waves-light @(item.isCompleted?"blue":"green") btn">@if (!item.isCompleted)
{ <i class="material-icons">done</i>}
else
{ <i class="material-icons">clear</i> }</button>
그래서 내가 그걸 어떻게 할 수
를? 고맙습니다.
"버튼 값은 변경되지만 클래스는 변경되지 않습니다."나는 당신을 오해합니까? 아니면 둘 다 바뀌지 않습니까? –