0

I have a cshtml page where I ask the user to provide some input data that I then need to concatenate into a string to build a dynamic LINQ query in my controller. This view DOES NOT use a model. Here is my html code so far.

<div id="filter">
Enter a customer name. It can be a part of a name to get broader results. (optional)
<br />
<input type="text", id="customer", value="") />
<br />
Enter a case status ( OPEN or CLOSED ), or leave blank to get both. (optional)
<br />
<input type="text", id="status", value="") />
<br />
Enter a date range to filter by date. (optional)
<br />
Start Date 
<input type="text", id="startdate", value="") />
End Date
<input type="text", id="enddate", value="") />
<br />
Enter a PromoID (optional)
<br />
<input type="text", id="promoid", value="") />
<br />
Enter a Complaint Code (optional)
<br />
<input type="text", id="complaintcode", value="") />
</div>

@Html.ActionLink("Export Case Data To Excel for Analysis", "CaseReport", "Reports",   "Excel", new { stringFilter = mystring })

The controller action has a string parameter called stringFilter. I basically need to build a string filter and pass it to the controller. I am using the Dynamic Linq Query library.

How can I get the string values from the DOM?

4
  • Don't still get your question.. What do you need? What does request.Form give you? Do you need the text-box values or what? Commented Feb 20, 2013 at 12:59
  • 1
    Possible duplicate? How to retreive form values from HTTPPOST (after which you'd just concatenate the strings in the normal way: "foo" + "bar") Commented Feb 20, 2013 at 13:23
  • @gaurav I basically need to just build a string from the text box values that I can send along to the controller action in the ActionLink. I gather the text boxes should be wrapped up in a form? When would I use request.Form? Commented Feb 20, 2013 at 17:59
  • I added to the original question that this view does not use a model. Many of the examples seem to assume a model is being used. Commented Feb 20, 2013 at 18:01

1 Answer 1

1

The one thing you can do is to concatenate them all in button-click event handler, somethingk like..

$('#form-input-submit-button').click(function() { /* do it here & then submit. */ });

But I recommend you to have in your MVC controller action method all the parameters you need

[HttpPost]
public void CaseReport(string promoId, string coplaintCode, ... ) { }

Or better to have strongly typed model

public class ReportModel
{
    public string PromoId { get; set; }
    public string ComplaintCode { get; set; }
    ...
}

So you could just:

[HttpPost]
public void CaseReport(ReportModel model) { /* Validate ModelState */ }

Actually, the model in MVC acronym is what you need.

But also you could do the

[HttpPost]
public void CaseReport(FormCollection form)
{
}

To see all the incoming data.

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

2 Comments

So if I create a viewmodel, I can bind the textboxes with Razor, then pass that model back to the controller action? I really would not need a form object with that method right?
@Ryan right. Just <input> element with the name corresponding to view-model's property name.

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.