Answer the question
In order to leave comments, you need to log in
ASP MVC How to get form data?
Hello! It seems like a trivial task, but I've been fighting for an hour.
there is a representation:
@using (Ajax.BeginForm("AddRecord", "Records",
new AjaxOptions
{
HttpMethod = "post",
UpdateTargetId = "target",
LoadingElementId = "sendingProgress",
InsertionMode = InsertionMode.Replace,
OnSuccess = "OnSucc"
}))
{
<fieldset>
@Html.HiddenFor(model => model.Event_Id, new { id = "hiddenID" })
.....
<p id="VievAfterGreate">
<h5>Вы можете:</h5>
@Html.ActionLink("Просмотреть запись", "VoewDetailed", "Records", new {id = Model.Event_Id }, new { target = "_blank" })
</p>
.....
<script type="text/javascript">
//так как модель еще не содержит айдишку записи (ее еще не добавили) - скрываю ссылку просмотра записи
$('#VievAfterGreate').hide();
//ПОЛУЧАЕМ ДЖЕЙСОН ПАРАМЕТР id добавленной записи, который отправил нам контроллер при добавлении записи
function OnSucc(data) {
$('#hiddenID').val(data.Id);
// проверяю - айдишка есть
alert($('#hiddenID').val());
//айдишка есть, строкой выше мы ее передали в модель - @Html.HiddenFor(model => model.Event_Id, new { id = "hiddenID" })
//теперь показываю ссылку для просмотра
$('#VievAfterGreate').show();
}
</script>
....
<span id="LinkViewAfterGreate"></span>
....
<script type="text/javascript">
function OnSucc(data) {
$('#Event_Id').val(data.Id);
var link = document.createElement('a');
link.textContent = 'Просмотреть созданную запись';
link.href = 'http://localhost:11733/Records/record/' + data.Id;
link.target = '_blank';
document.getElementById('LinkViewAfterGreate').appendChild(link);
.....
</script>
Answer the question
In order to leave comments, you need to log in
Look at the model object that you pass to this View. If it is empty, then what kind of id can we talk about ?!
Alternatively, check the case of the Id entry in the route and in your entry. There is a chance that Razor simply does not understand which part of the link to attach it to.
PS You have DARKNESS(!!!) typos in your code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question