jquery - Using @HTML.Action with Parameters to C# controller -


In the view, user will check 1 or more names from what is shown ...

  & lt; Form name = chkAttend method = post onsubmit = 'return valid (this)' & gt; & Lt; Div & gt; @if (Model.evModel.Participants! = Null) {foreach (participated in model. Avimodel, partner) {& lt; Div & gt; @if (@ fi.AttendedFlag! = True) {& lt; Input type = "checkbox" id = "c_@fi.EnrollmentId" name = "MyCheckboxes" value = "@ fi.EnrollmentId" /> & Lt; Label for label = "c_@fi.EnrollmentId" aria-multiselectable = "True" & gt; & Lt; / Label & gt; & Lt; Period & gt; & Lt; / Span & gt; @ Fi.EnrollmentId @ fi.ParticipantName} & lt; / Div & gt; }} & lt; Input type = submit value = "confirm presence" & gt; & Lt; / Div & gt; & Lt; / Form & gt;   

After selecting names, call the function to check names. The name checked is required only to pass the controller. Problem - I get an error message: Error 49 The name 'id' does not exist in the current name

  Validate the function (form) {var id = "" (var i = 0; I & lt; document.chkAttend.MyCheckboxes.length; i ++) {if (document.chkAttend.MyCheckboxes [i] check) id + = document.chkAttend.MyCheckboxes [i] .value + ","} if ( ID == "") {Warning ("Keep a check mark next to the participants of the event")} {@ Html.Action ("ConfirmAttendance", "Admin", new {eventid = @ Model.evModel.Id, enrollid = Id})} description is false; }   

How can I pass only checked items as parameters for the function in my controller?

You can not inject such server side partial views in your code like this. As it stands (if you come around the id variable reference problem), you will actually put a partial view inline in your Javascript which will make invalid JavaScript!

Instead, just behave as a client-side and inform the feed on that page, which will require Javascript, which is easy to access. You can inject the global variable through the injected JS code, but I strongly recommend that exercise.

Instead your MVC page controller can inject the action URL and event ID as the data - attribute, like this:

  & lt; Form name = "chkAttend" method = "post" data-action = "@ Url.Content (" ~ / Admin / ConfirmAttendance ")" data-eventid = "@ Model.evModel.Id" & gt;   

Ensures the use of the URL. The URL is always site relative, even when hosted as a virtual application.

Your client-side code can then select prices from the form, add selected IDs, and call the server action using AJAX:

  Function valid (form) {var action = $ (form) .data ('action'); Var eventID = $ (form) .data ('event');   

Fun is starting because you have to call the server from client-side, e.g. Do something with the result with your selected option and to change the display. $ .ajax ({// Use url URL (Action + Event ID + ID) URL: Action + "? Eventid =" + eventId + "and enrollid =" + id, type : "PUT" success: function (data) {// do something with server result}});

You do not show your administrator's confirmation confirmation action, so I can not even guess what you are returning. Make sure it is appropriate (Boolean can be as simple as a result or can be complex as a partial view to put in the page).

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -