我有文本框。悬停时我可以编辑文本框内容。编辑后我可以保存更改,但是这次文本框的值不会改变,只有在刷新之后。如何更改文本框的值?
样本:
<input type="radio" name="SelectedSavedSearches" id="Saved_search_<%:s.Value %>" value="<%:s.Value %>" />
<label for="Saved_search_<%:s.Value %>"> </label>
<input type="text" class="saved-search-name def-text-input" value="<%: s.Text %>"/>
<button class="saved-search-rename"><strong>Save</strong></button>
js:
$('.saved-search-rename', container).unbind('click').click(function () {
var context = $(this);
var name = context.closest('p').find('.saved-search-name').val();
if (name != undefined && name.trim() != '') {
var id = context.closest('p').find('input[name="SelectedSavedSearches"]').val();
$.ajax({
url: '/Account/RenameSavedSearch',
type: 'POST',
dataType: 'JSON',
data: { ssId: id, newName: name },
success: function (response) {
if (!response.result) {
btDialogs.Error(response.message);
}
}
});
return false;
} else {
btDialogs.Error('New Name can\'t be empty');
}
return false;
});
行动:
[HttpPost]
[ProfileVerification]
public JsonResult RenameSavedSearch(int ssId, string newName)
{
if (LoggedUser == null)
return Json(new {result = false, message = "Not Authenficated"});
var search = _listingManagementService.GetSavedSearch(ssId);
search.Name = newName;
var confirmation = _listingManagementService.SaveSearch(search);
return
Json(
new
{
result = confirmation.WasSuccessful,
message = confirmation.WasSuccessful ? "Success" : confirmation.Message
});
}