Showing and posting in separated actions in a main view - c#

I would like to explain my scenary: I have a form that is composed by 2 other partial views.
The idea is the following
The main Form show details about a Budget.
The second show a form to send messages.
The third show a form to send offer bids;
I would like that, when I do a Post in the 2nd ot 3rd form, the application return the main form. but, it is returning the form that was Posted.
It would work like I was using IFRAME... in other words, when I do a Post, it reflect only in the form that was Posted.
I am doing this form with MVC in C#.
Any tip?
I tried to use [ChildActionOnly], but I suppose that isn't what I am looking for.

If I understand your problem correctly,you must use "return View("MainView");" instead "return View();"

The right Answer is:
I created a new View;
I changed the strucure Html.Beginform to Ajax.BeginForm;
Used the jqueryunobtrusive.
You can see an example here: enter link description here

Related

I want to preserve form values during multistage registration with different view on next and previous button

I want to create multi stage registration form where i would be having next and previous button like when moving from 1st step to 2nd step in registration form and then coming back to again 1st step with previous button then 1st form should retain all its values.
I am using this code from Darin Dimitrov answer:multi-step registration process issues in asp.net mvc (splitted viewmodels, single model)
But in Darin Dimitrov answer problem is dat with this line:
#Html.EditorFor(x => currentStep, null, "")
I would be having different different fields with slight modification of design too on every new registration form and i would be having progress bar too on which i will update progress bar status.
So in Darin Dimitrov answer i would like to use different different View.Is that possible with Darin Dimitrov answer to use different views?
Or if anybody having another solution then please do post your solution.

using ajax to post to server of a partial view form

I am new at using ajax, I have to add the form data onto a post so that it can be added to the server. but the tricky part is that the form data is a partial view on a dialog box. i would like to know how i would be able to use ajax in order to get a hold of this data so that it can be put back on to a database.
make a function on click of a button in the dilog box
Then un that function use $.Post({"Controller/Action", {Parameter List}})
where PArameter List will contain the values of controls Like
Parameter1=document.getelementbyid('Textbox1').value;
so on ....
and make a action method in controller using [HTTPPost]
you can check syntax from here
http://www.codeproject.com/Articles/426765/post-and-get-in-MVC-Razor-JQuery
Please Click the answer as useful if it serves your problem.

Display form in pop up

i have two cshtml page one which has the link the makes the popup appear, and another with just the form data and would like to know how i would be able to display the form on the popup, as i am using MVC, to create the form, the plage which has link on is in the ~/views/client/index.cshtml while thr form is ~/views/fb/CreateOrEidt.cshtml the colller is called "FB" and the methos to call is edit, it take the parameter Id
I have tried #hmtl.renderpartial, #html.renderaction, #hmtl.partial, #html.action,
I have also tied these method with a { after the # and the end, doesnt give me a error bust still doesn't display information
The error which i get is razor canot convert type object to void
It's a little unclear what you're trying to achieve but from the error you've mentioned when calling Html.RenderAction you need to call using something like:
#{
Html.RenderAction("ACTIONNAME");
}
Calling the other methods against an action view won't work.
If you're trying to display a view inside a popup though you want to be careful that you don't end up including your layout page etc as this is potentially not the look you're going for..!
The pattern I generally implement for things like this is to simply partial out the form bit that I need to reuse and call renderpartial to display this where I need it. This renders just the html I'm after then and not the whole view (+ layout(s)).

How to prefill a form with post data in ASP.NET

I need to populate a form in the main page which on being submitted opens a lightbox which contains another form .
I was planning to submit the form using Post as that seems to be the only way I can define which iframe to open in the lightbox .However my question is that how do I pre-populate the second form with the first forms data when I use the submission as POST
I am using ASP.NET and C#
I apologize for the naive question but I am still playing around with ASP.NET
We dont have many details on items such as - is there a redirect? whats the second form? how are you handling controls.. etc
Check this out to start. If you really need to send values across separate requests there are various ways to do this, but specify if this is what you are trying to do.
http://msdn.microsoft.com/en-us/library/ms178139.aspx
Use the Form collection in the Request object on the second form. The name in the collection is the same as the name in the name/value pair you're using in the post.
TextBox1.Text = Request.Form["someName1"];
TextBox2.Text = Request.Form["someName2"];
Etc.

How can I set a variable in my pages javascript based on my controller action in ASP.NET MVC?

So, I have a page that looks like the following:
alt text http://img704.imageshack.us/img704/5973/croppercapture3.png
This is my basic messaging inbox. I have 2 pages right now, Inbox and Sent (there will eventually be others). These both share the same View, and just have 2 different actions to populate the appropriate data.
The elements on the right-hand side (the message list) is a partial view which has its data populated based on my two controller actions Inbox(int? page) and Sent(int? Page).
So, I have one view "MessageView" and one partial view "MessageList" shared between Inbox/Sent.
However, I now have to get those arrow buttons ("<" ">") working using Ajax. I know how to use jQueries ajax calls well enough, and I know how to render the result of the action call (which returns a partial view).
The problem comes from the fact that the javascript that makes these pagination ajax calls needs to know two things:
What the current page is (whether it be /messages/inbox or /messages/sent)
What the current page is (specified in the query string, ie /messages/inbox?page=2).
Without knowing which page I'm on (Inbox or Sent), it wont know which url to make the ajax call on. Should it make the postback to /messages/inbox or to /messages/sent?
If I wasn't making these messages load with Ajax it would be as simple as loading the appropriate url into the link tags for the "<" and the ">" buttons. But I can't, because part of my requirements states that it must load the messages below without visibly refreshing to a new page.
In JavaScript you can check window.location.pathname to see the pathname section of the current’s page’s URL.
window.location.search gives you the query string.
When the user clicks the Inbox or Sent buttons, you need to rewrite the URLs in your arrows so that they point to the right place.

Categories

Resources