1

我想将值 TextBoxFor 传递给我的更新操作,但我不知道该怎么做。我知道我必须通过某个地方,可能是这样的……新的 { $id = "Status"}。我必须按一个用于增加和一个用于减少。但主要问题是将文本框的值传递给我的操作。这是我的 InventoryUpdateDto 类和操作

public class InventoryUpdateDto 
    {
        public int InvId { get; set; }

        [RegularExpression("^[0-9]*$", ErrorMessage = "Status must be numbers")]
        [Required(AllowEmptyStrings = false)]
        public int Status { get; set; }
    }

[HttpPost]
        public async Task<ActionResult> Increase(InventoryUpdateDto inventory)
        {
             using (context)
            {
                if (!ModelState.IsValid)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                    var prRecord = await context.Inventories.FindAsync(inventory.InvId);
                    prRecord.Status = prRecord.Status + inventory.Status;
                    context.Inventories.Add(prRecord);
                    context.Entry(prRecord).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                    SllitHub.NotifyCurrentInformationToAllClients();
                    return RedirectToAction("Index");
            }

         }

我的表格:

@using (Html.BeginForm())
        {
            @Html.HiddenFor(model => model.InvId)

            <div class="well well-sm col-lg-6">
                // How can I send value of this TextBox value to my action?
                // I tried but could not update
                @Html.TextBox("Status", null, new { @class = "form-control" })
                // This one is better I can Update but it's not empty textbox
                @*@Html.TextBoxFor(model => model.Status, new { @class = "form-control" })*@
                @Html.ValidationMessageFor(model => model.Status)

                <input type="submit" name="response" value="Increase" formaction=@Url.Action("Increase", "Home") formmethod="post"/>
                <input type="submit" name="response" value="Decrease" formaction=@Url.Action("Decrease", "Home") formmethod="post"/>
            </div>

        }

我也试过这样

@Html.TextBox("Status", null, new { @class = "form-control", @id = "Status" })

先感谢您!

4

0 回答 0