2

How do i pass data from a Html.EditorFor to myAction in myController?

This is my Editor:

<div class="editor-label">
            @Html.LabelFor(model => model.Quote_Currency)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Quote_Currency, new { })
            @Html.ValidationMessageFor(model => model.Quote_Currency)
        </div>

This is my controller action:

public ActionResult SaveQuote(FxQuote quote, string Quote_Currency)
        {


                objQuote.Quote_Currency = Quote_Currency;

                dcfx.FxQuotes.InsertOnSubmit(quote);
                dcfx.SubmitChanges();


            return View();

Here,i was trying to have a parameter with the same name as my Editor but that did not work. Please help.

4
  • 2
    Is it in the <form>? What do you see in the POST request? Commented Apr 23, 2012 at 15:23
  • The editor is in a form (Html.BeginForm).I am using LINQ. Commented Apr 24, 2012 at 7:51
  • Oh and i made a mistake in the above code.The 'objQuote' in line2 of my controller action should be 'quote' Commented Apr 24, 2012 at 7:53
  • As Xharze said, what type is "model" on the view (ie what model are you declaring). ION addition, when you POST, can you use Fiddler to see what data is being posted? is there a Quote_Currency; Commented Jun 8, 2012 at 10:53

2 Answers 2

1

You can add a FormCollection collection as an extra parameter to your controller method. That collection will hold all data passed from the view in the controller. You can use the debugger to explore which data is exactly being sent to the controller.

Sign up to request clarification or add additional context in comments.

Comments

0

Why dont you just change the action to accept your model?

Something like this:

 public ActionResult SaveQuote(ModelType model) 
 { 


            objQuote.Quote_Currency = model.Quote_Currency; 

            dcfx.FxQuotes.InsertOnSubmit(model.Quote); 
            dcfx.SubmitChanges(); 


        return View();
  }

Alternatively you can change it to accept a form collection as mentioned in another answer:

 public ActionResult SaveQuote(FormCollection collection) 

Hope this helps

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.