参数string Temat
当我点击按钮在哪里的问题是空的? 它的外观好不好?
file.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});
}