0

I'm trying to make a small table, which can set the amount of columns through an "input field". I generated the the input field by following code (+ button):

@Html.EditorFor(model => model.Columns.Count, new { @class = "text-center control-form", @id = "countID" })
@Html.ValidationMessageFor(model => model.Columns.Count)
<button type="button" class="btn btn-primary" onclick="location.href='@Url.Action("CreateTable", "Home", new { count = VARIABLEHERE })'">Update</button>

I basically try to set the input of the @Html.EditorFor(model => model.Columns.Count .. as parameter of the function, executed by the button.
I tried using @Model.Columns.Count, but that's not working, because the count doesn't change through the input field.

Any ideas how to fix this?

1
  • 1
    Razor runs on the server. As soon as you see the page rendered, nothing will be updated anymore. You need JavaScript for what you want Commented Jul 12, 2018 at 14:21

1 Answer 1

1

Try put inside a form (using or not the html razor helper):

@using (Html.BeginForm("CreateTable", "Home", FormMethod.Post, null){ your code... }

Button should be of submit type..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.