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?

Ryan
  • 650
  • 3
  • 15
  • 49
  • 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? – Gaurav Pandey Feb 20 '13 at 12:59
  • 1
    Possible duplicate? [How to retreive form values from HTTPPOST](http://stackoverflow.com/q/5088450/211627) (after which you'd just concatenate the strings in the normal way: `"foo" + "bar"`) – JDB Feb 20 '13 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? – Ryan Feb 20 '13 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. – Ryan Feb 20 '13 at 18:01

1 Answers1

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.

AgentFire
  • 8,944
  • 8
  • 43
  • 90
  • 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 Feb 20 '13 at 18:29
  • @Ryan right. Just `` element with the name corresponding to view-model's property name. – AgentFire Feb 20 '13 at 19:26