单击按钮时参数string Temat
为空哪里有问题?看起来还好吗?
文件.cshtml
@using (Html.BeginForm())
{
<table class="edt" style="float: left; width: 600px; margin-top: 5px; background-color: white;">
<tr>
<td class="labelm">
@Html.LabelFor(m => m.Temat)<span id="Temat_2" class="a">*</span>
</td>
<td>
@Html.TextBoxFor(m => m.Temat, new { id = "Temat" })
</td>
</tr>
</table>
<input type="button" value="save" onclick="Save();" />
}
<script type="text/javascript">
function Save() {
var Temat = $('#Temat').val();
$.ajax({
url: '@Url.Action("DodajTematSave", "StronaGlowna")',
dataType: "json",
data: { Temat: Temat },
type: "POST",
async: false,
error: function() {
},
success: function(data) {
if (data.Success) {
alert('success');
}
}
});
}
</script>
控制器中的 JSON 方法:
public JsonResult DodajTematSave(string Temat)
{
var model = new StronaGlowna();
if (!TryUpdateModel(model) || !ModelState.IsValid) // podładowanie yield
{
}
string chceSprobowac = Temat;
return Json(new { Success = true});
}