1

I have a simple form based on a model.

One of the features I have to support is the ability to create a url of the current paraments of the model. For example:

Form Begin
  Model.Name
  Model.Age
Form End

Then in javascript some how get:

http://Site/Controller/Action?Name=Bill&Age=45

Is there a helper that will take the current state and gen a Url?

The reason is that I need to be able to open a new window with the values of the model while leaving the form and page as is.

0

3 Answers 3

2

You should be able to do something like this in your javascript

var url = "@Html.Action("Action", "Controller", new { Name = Model.Name, Age = Model.Age})";
window.open(url);
Sign up to request clarification or add additional context in comments.

Comments

1

Use window.location and then window.open to open it in a new window/page/tab. For example: var myURL = window.location.href; and then use window.open(myURL)

Comments

0

AFAIK, there isn't a way to get what you are asking (nice idea though). I upvoted NKD because of the second part of your question which was on how to open the browser in a new window (perhaps you already knew how to do this).

you would need to use the JQuery/Javascript way of obtaining the values you desire. Alternatively you could make a quick client helper where you give it the key name you are after, it would find it and give it back to you i.e:

function GetValueFromForm(key)
{
   return $('#' + key).val();
}

then you call it:

var url = '/SomeAction?name=' + GetValueFromForm('Name') + '&age=' + GetValueFromForm('Age');

Alternatively, if the data is NOT changing then just use the Model values in your javascript:

var url = '/SomeAction?name=' + @Model.Name + '&age=' + @Model.Age;

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.