-1

I've been given some 3rd party examples of dialog re-usage and I'm wanting to look at using some elements to pull values end users have selected, examples given have a JS function handling the selected value, how would I pass this to the controller action below? Any help or pointers would be massively appreciated.

View JS function

 } function fileSelected(data) { var el = document.getElementById("fileId"); if (data) el.innerText = data.selected; else el.innerText = "None"; } 

Controller action I'd like it to land

 [HttpPost] public ActionResult fd(string Fid) { Debug.WriteLine(Fid); return View(); } 
6
  • How do you want to send this information to the server? Is the user posting a form? Clicking a link? Is the client-side code making an AJAX request? Something else? What is the user doing which involves making a request to the server, and what data are you including on that request?
    – David
    CommentedJan 25 at 15:57
  • It's a dialog box that they'll be presented with, they select 'files' & what's reported back is the fileid's this is what I want back server side - how this comes back? I'm happy with whatever is the easiest, once I have the data I'm good to go.CommentedJan 25 at 17:15
  • Sorry forgot to tag you @David - So I need to something to trigger the actionresult from within the js function, there is no form posting so I can't use Html.BeginForm.... from what I can see, the application the user is using is 3rd party and I have no access other than what is selected then assigned within that js function so I just need to grab that value which will then be passed eventually to my application.CommentedJan 26 at 9:59
  • I guess it sounds like you want to use AJAX then? If that’s the case then you are certainly encouraged to get started with some examples or tutorials and make an attempt.
    – David
    CommentedJan 26 at 11:19
  • Yes @David that's what I've stumbled across, I'm receiving a 404 with the below but the output I'm getting (localhost:44396/Home/fd?fid=ACTIVE!34837543.1) appears correct or am I missing something? ``` $.ajax({ url: "/Home/fd", data: { Fid }, type: 'GET', success: function (result) { console.log("Works"); }, error: function (result) { console.log("Not Working"); } }); ```CommentedJan 26 at 12:08

1 Answer 1

0

If you want to send value or data to Controller, you have to send it with AJAX.

var item; item.append("Fid", your data); $.ajax({ url: "@Url.Action("fd", "your Controller name")", type: "post", data: item, cache: false }); 

if you want give from controller any result, can attached this code end of above code (instead of ;)

.done(function (result) { this result have anything you return to this } 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.