Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate a model value on Html.TextBoxFor() onchange event without submitting
    text
    copied!<p>I have a textbox that I call in my view like so:</p> <pre><code>@Html.TextBoxFor(Function(m) m.ActivityIDReturn) </code></pre> <p>What I'd like to be able to do is whenever a value is inserted into this textbox I would like it to update the model without having to hit any type of submit button. Several elements are populated in the view by the value of this textbox.</p> <p>So ideally the textbox would looks something like this:</p> <pre><code>@Html.TextBoxFor(Function(m) m.ActivityIDReturn, new with {Key .onchange=UpdateModel()}) </code></pre> <p>or</p> <pre><code>@Html.TextBoxFor(Function(m) m.ActivityIDReturn, new with {Key .onchange= RETLog(ActivityIDReturn:=ActivityIDReturn)}) </code></pre> <p><em>RETLog() being the function that creates the view in the firstplace.</em></p> <p>So far the only way I've been able to accomplish this is:</p> <pre><code>@Html.TextBoxFor(Function(m) m.ActivityIDReturn, New With {Key .onchange = "javascript:submit()"}) </code></pre> <p>But I can only imagine what horrible side effects might come from this kind of thing. </p> <p><strong>EDIT: Exactly what I am trying to accomplish here</strong></p> <p>In My Model I have this: </p> <pre><code>Public Property PS As RecordsTaskView Get Return GlobalVar.db.PS.RecordsTaskViews.Find(ActivityIDReturn) End Get Set(ByVal value As RecordsTaskView) value = GlobalVar.db.PS.RecordsTaskViews.Find(ActivityIDReturn) End Set End Property </code></pre> <p>In my view I have This:</p> <pre><code> @Html.LabelFor(Function(m) m.ActivityIDReturn) @Html.TextBoxFor(Function(m) m.ActivityIDReturn, New With {Key .onchange="javascript:submit()"}) @Html.DisplayFor(Function(m) m.PS.RefActionID) @Html.DisplayFor(Function(m) m.PS.QutDesc) @Html.DisplayFor(Function(m) m.PS.TaskDesc) @Html.DisplayFor(Function(m) m.PS.CltCode) @Html.DisplayFor(Function(m) m.PS.CltDesc) @Html.DisplayFor(Function(m) m.PS.BenIDin) </code></pre> <p>Basically all of these DisplayFor are populated by the value of this textbox. I would like these DisplayFor values to populate when the user enters a value in the textbox without the user having to refresh the page, or hitting enter or hitting any buttons.</p> <p>Here is a view at my code in it's entirety: <a href="https://gist.github.com/aaronmallen/7042328" rel="nofollow">https://gist.github.com/aaronmallen/7042328</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload