Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear friends,

I was searching for the following;

I have a href which got a URL.Action.

@Url.Action("Index", "Action", new { ID = 1 })

The ID need to be hidden value from a input field.

<input type="text" style="visibility:hidden;" class="SelectedAction" value=""/>

The value of this hidden input field is filled with jquery. I don't want to create a form so wondering how I can get the value of the hidden input into de URL.Action ID.
Any options to do this without a form? using jquery or javascript.


Ajax submit the only option so far I found.

XML
<div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Close</a>
    <input type="button" value="Send" onclick="submit()" />
</div>

<script>
    function submit() {
        $.ajax({
            url: @Url.Action("act", "con") + '?param1=' + $('#myFormSubmit').value +
                                              '&param2=' @Model.Obj.Value1 +
                                              '&param3=' + @Model.HashedValue,
            type: 'POST',
            // ... other ajax options ...
        });
    }


This is the only option?
Posted
Updated 16-Oct-15 2:23am
v4
Comments
F-ES Sitecore 16-Oct-15 8:36am    
It depends if you just want to call the action or navigate to the page. You could store the value in a cookie via jquery and access it server-side that way. However I suspect what you're doing is trying to resolve a problem via a flawed method.

http://forums.asp.net/post/5825782.aspx
Wessel Beulink 16-Oct-15 8:52am    
Yeah maybe it's just waste of time.

1 solution

As you said, hidden input value is filled using jQuery, you can do the following:
HTML
@Url.Action("Index", "Action", new { @class = "myLink" });
<input type="text" style="visibility:hidden;" class="SelectedAction" />

JavaScript
$(".myLink").attr("href", "/Action/Index?id=" + $(".SelectedAction").val());


-KR
 
Share this answer
 
v2
Comments
Wessel Beulink 16-Oct-15 9:48am    
This is confushing me. The @class = "mylink" is always null in this case so you passing a null value to a controller?

public ActionResult Index( int ID ) <-- will be null because you not giving a value to the controller.
Krunal Rohit 16-Oct-15 10:00am    
Not passing myLink to controller. It's a CSS class. I have used it so that I can access that link using it in jQuery.

-KR
Wessel Beulink 20-Oct-15 3:52am    
thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900