I want to take some info from my model, edit one variable and pass it to post function. Here is my model:
public class TaskInputModel
{
[Required]
[Display(Name = "Input Value")]
public decimal Value { get; set; }
public long InputId { get; set; }
public MetriceModelTaskShedule[] Tasks;
}
and this is my Index.cshtml:
@model MetriceWeb.Models.TaskInputModel
@foreach (var item in Model.Tasks)
{
using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
@Html.LabelFor(model => item.Task)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Value)
@Html.ValidationMessageFor(model =>model.Value)
</div>
@Html.Hidden("Model.InputId", Model.InputId)
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
}
I’m receiving this like that:
[HttpPost]
public ActionResult Index(TaskInputModel model)
{
...
}
When I’m submitting only InputId has some value, Value is always 0. When i delete line: @Html.Hidden(“Model.InputId”, Model.InputId) Value is ok, but i don’t know how to receive InputId. Can you tell me how can I do this?
Problem solved. I just had to use @Html.Hidden(“InputId”, Model.InputId) instead of @Html.Hidden(“Model.InputId”, Model.InputId)