I want this:
#using (Html.BeginForm("bgcTest", "CompaniesController"))
{
<p>
Ange BolagsID: <br />
<input type="text" name="BolagsID" />
<input type="submit" value="bgc test" />
</p>
}
To fire this event:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult bgcTest(string BolagsID)
{
...
}
But I get the error:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /CompaniesController/bgcTest
I can't for the life of me figure it out. If I just make an actionlink I get my method to fire, but I need an user inputted variable to go along with the fireing.
What am I doing wrong?
(This is my first time with MVC and I have to implement some functionality into an already existing project. For work.)
The name of your controller class (.cs file) is CompaniesController.cs.
That's a convention (default behavior) where MVC will automatically identify it as a controller.
When referencing this controller in your view, use Companies only.
If you use CompaniesController MVC will try to find a CS file named CompaniesControllerController.
Correct code:
#using (Html.BeginForm("bgcTest", "Companies"))
Related
The required anti-forgery cookie
"_RequestVerificationToken..." is not present
I am getting this error on one specific machine. On that machine user gets it in two different browsers. rebooting, restarting browser, cleaning cookies, and restarting IIS App pool didn't solve the issue.
On different machines this web app works fine.
conttroller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(MyModel thisObject)
{
}
page:
<body>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
....
<input type="submit" value="Save" class="btn btn-primary" />
}
Any idea what's going on here?
When adding the AntiForgeryToken reference in the form, it generates a hidden input marked name=__RequestVerificationToken. Get the value of that input and add that to your call as a parameter.
Check the answer to this post for details include antiforgerytoken in ajax post ASP.NET MVC
In a ASP.NET MVC website; does every view need to have a corresponding/associated Model and Controller?
I am building the bare bones of my website; so I have created all the views but not the Models or Controllers yet. I want to be able to view a page (that contains no content associated with a model or any functionality that a controller should handle - yet). So at this point every view (cshtml page) is a static HTML page.
But when I go to access any view/page I get the error:
The resource cannot be found. Description: HTTP 404. The resource you
are looking for (or one of its dependencies) could have been removed,
had its name changed, or is temporarily unavailable. Please review
the following URL and make sure that it is spelled correctly.
Requested URL: /TeamMember/raiseIssue
raiseIssue.cshtml content:
#{
Layout = "layouts/main.cshtml";
}
<form action="#ViewBag.PostUrl" method="post">
<div class="row feedback-input text-center">
<textarea name="Text"></textarea>
</div>
<div class="row text-center">
<button type="submit" class="btn btn-default btn-standard">Submit</button>
</div>
</form>
MVC do not allows to browse the view directly. What you can do is create empty controller method like below
public ActionResult RaiseIssue()
{
return View();
}
in controller TeamMemberController
One other thing, please make sure that proper route are configured in RouteConfig.cs
I hope using this method you will be able to browser the view with writing much code in controller or model/
So I have a form on my shared layout page that I want to simply post a text string to. I currently have a breakpoint sitting at the beginning of that action in the controller to test the form is working but it appears that it never gets there because it never hits the breakpoint. Here is my code anyone know what I am doing wrong?
View:
<form action="/RespondentSearch/Search" method="post" class="sidebarSearch">
<input type="text" name="search" placeholder="respondent search..." id="ac" class="ui-autocomplete-input" autocomplete="off" /><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
<input type="submit" value="" href="#moadalSearch" rel="lightbox" />
</form>
Controller:
public class RespondentSearchController : Controller
{
[HttpPost]
public ActionResult Search(string search)
{
string stuff = search;
return View();
}
}
My Visual Studio Debug Console though reads like there is an exception?
Following route: {controller}/{action}/{id} for request: http://localhost:56554/RespondentSearch/Search
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
Following route: {controller}/{action}/{id} for request: http://localhost:56554/Home/Login
Following route: {controller}/{action}/{id} for request: http://localhost:56554/
My Developer Tools Browser Debug:
Request URL:http://localhost:56554/RespondentSearch/Search
Request Method:POST
Status Code:302 Found
search:asdf <--- This is what I was typing in
It appears it is getting there but I am not hitting my breakpoint still? I also added a temp view for it to just output something when its there and still nothing. It is like it is completely avoiding my controllers action.
I'm using umbraco with extensionless urls.
I've inserted a simple piece of HTML in one of my masterpages (en/test) :
<form method="post" enctype="multipart/form-data">
<input type="submit" />
</form>
When I press the submit button, I get a 404. The path is exactly the same and should exist.
When I remove the enctype part, the submit occurs fine.
I can't figure out how to fix this, but I bet it has something to do with the rewriting.
I also tried the following without success:
<form method="post" enctype="multipart/form-data" action="/en/test">
<input type="submit" />
</form>
<form method="post" enctype="multipart/form-data" action="/en/test.aspx">
<input type="submit" />
</form>
The only page where I CAN use the enctype attribute, is on the actual homepage. I guess this has to do with the fact that the physic default.aspx exists.
=============== UPDATE =================
There is only one form element in the page, the one that I've inserted. So a "whole page" form element is certainly not the case. Secondly, yes the form is in theory posting back to itself. I also tried an empty action tag, plus an action tag with the full url as suggested, with the same results.
When I either use the following scenario's:
No action attribute
action=""
action="{relative path}"
action="{absolute path}"
I end up on exact same URL as where I fired the submit from. But it's a 404. When I press the enter key in my address bar, no 404, I'm back at my original page with the same URL.
First question I should ask is do you get a 404 when you browse to "/en/test" or "/en/test.aspx". For the form to post back to itself try an empty action e.g. action="" or writing the current url into the action attribute. And one further question, do you have another form wrapped around your page with the runat="server" attribute because if you have you will end up with nested forms which will also cause you issues.
On a side node I would strongly suggest upgrading your installation to at least v4.11.4 due to a bug that was introduced in 4.10. Please see the following for details...
Trying to publish a root node (parent) after unpublishing a child result in a YSOD:
http://issues.umbraco.org/issue/U4-1491
Path Fixup
http://our.umbraco.org/projects/developer-tools/path-fixup
I have two websites A and B both written in ASP.NET MVC 3. In website A there is a form which needs to be submitted to website B via POST method. The user has option to post it directly or after encrypting the values.
When I submit form without encryption it is simple form.submit() and I am able to get the values in website B using FormCollection object. But when user selects submit after encryption, I redirect to another action on website A itself where encryption occurs and then this encrypted data is placed in a hidden textbox in the corresponding view and then auto submitted on page load using jQuery to website B. But now I am unable to get any values in FormCollection object on website B.
What could the problem be? Is this happening because of any security feature to prevent XSS or something similar?
Its doubtful its from XSS protections - in that case you would see an exception.
Load up fiddler and make sure you see this data in an element inside your form that is getting posted to website b. if its there in the form that is being submitted - it should be available.
Any reason for not using HTTPS and submitting directly the form to site B?
<form action="https://siteb/someaction" method="POST">
<input type="text" name="key1" value="value1" />
<input type="text" name="key2" value="value2" />
<input type="text" name="key3" value="value3" />
<input type="submit" value="Go ahead" />
</form>
If there is any reason in the case you are encrypting the values into a single hidden input and submitting the form containing this hidden field using javascript, only the value of the hidden field will be sent to site B. So for example if you had the following form:
<form action="http://siteb/someaction" method="POST">
<input type="hidden" name="encrypted" value="some encrypted value" />
</form>
on site B you would fetch the encrypted value like this (don't use FormCollection, it's kinda ugly compared to view models):
[HttpPost]
public ActionResult SomeAction(string encrypted)
{
// TODO: decrypt the encrypted value here to get the orginal string
...
}
And an even more elegant way would be to have a view model defined on site B and a custom model binder for this model that will do the decryption so that the action looks simply like this:
[HttpPost]
public ActionResult SomeAction(SomeViewModel model)
{
// Directly use the model with all the fields in it.
// The custom model binder will take care of the creating it
// from the encrypted request string
...
}