Asked by:
pass data from one view to another view but don't show in url

Question
-
User-1634604574 posted
i have this code which send data from view1 to view2
view1
window.open("edit_antibiotic?series=" + series + " &username=" + $("#username").val() + "", "_self");
view2 (in view2 i will get the data from view1 by request)
<input type="hidden" id="username" value="@Request["username"]">
<input type="hidden" id="series" value="@Request["series"]">
my problem is show the data in the url when i open view2 i don't want to show that request in the url how can i do it?
Monday, February 11, 2019 12:43 PM
All replies
-
User475983607 posted
i have this code which send data from view1 to view2Views do not pass parameters to Views. Views pass parameters to Actions.
my problem is show the data in the url when i open view2 i don't want to show that request in the url how can i do it?Your example is using an HTTP which by definition passes parameters in the URL. Use an HTTP Post to pass parameters in the message body.
However, your design does not make logical sense. Can you explain what you are trying to do a a high level.
Monday, February 11, 2019 2:29 PM -
User1724605321 posted
Hi zhyanadil ,
Do you need to redirect in javscript ? If not , you can use form to post the data to action :
https://www.aspsnippets.com/Articles/ASPNet-MVC-Form-Submit-Post-example.aspx
https://forums.asp.net/post/5540092.aspx
Best Regards,
Nan Yu
Tuesday, February 12, 2019 3:08 AM -
User-474980206 posted
use a form post. after your current form, add (note use of name instead of id):
<form method="POST" action="edit_antibiotic" id="edit_antibiotic" target="_blank"> <input type="hidden" name="username" value="@Request["username"]"> <input type="hidden" name="series" value="@Request["series"]"> </form>
then replace window.open() with:
document.getElmentById("edit_antibiotic").submit();
Tuesday, February 12, 2019 7:52 PM -
User-1634604574 posted
i have this error
document.getElmentById is not a function
in that line
document.getElmentById("edit_antibiotic").submit();
Wednesday, February 13, 2019 11:05 AM -
User475983607 posted
i have this error
document.getElmentById is not a function
in that line
document.getElmentById("edit_antibiotic").submit();
You have a typo...
document.getElementById("edit_antibiotic").submit();
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
Wednesday, February 13, 2019 11:31 AM