Showing posts with label parameters. Show all posts
Showing posts with label parameters. Show all posts

01 July 2015

Pass arbitrary parameter to partial view in ASP.NET MVC

I had a chunk of HTML that needed to repeat in a few places, so it made sense to throw it into a partial view. However, each chunk had to have a unique ID for a Bootstrap collapse component. So a parameter needed to be passed in. Some research revealed a rather simple, elegant way in this article. Just pass it as the partial view's model:

@Html.Partial("~/Views/Shared/_TestimonialSubmitPartial", "1")

Then, in the partial view, read it using @Model -- it's the only value passed in, so no dot notation is necessary. Each time I'm using the partial view, I change the value.

In the partial view, I set the data-target of the Bootstrap button to the concatenated ID and also set the collapse div to that same value:
<button class="btn btn-default" 
    data-target="#testimonial-submit-instructions-@Model" 
    data-toggle="collapse" type="button">
    Submit Testimonial
</button>
<div class="collapse" id="testimonial-submit-instructions-@Model">
.....
</div>

04 November 2008

Wireshark - Must-have Utility for All Flex Developers

I was wrestling with a very subtle problem today: The Flex app was passing some variables to a Java servlet via an HTTPService,

var params:Object = new Object();
params.ServiceType = "INITIALIZE";
params.SearchID = searchID.text;
params.Description = searchDescription.text;
serviceGridReader.send(params);

Using the Wireshark tool, I filtered the capture to only give me the packets for my server. I noticed that the above params data was being sent to the server as XML. Hmm. I had the following further up in the code,

serviceGridReader.contentType = "application/xml";

I created a simple HTML page with a form and a submit button, passing the same data in hidden fields. Lo and behold -- the servlet worked fine with that. Using Wireshark, I noticed the data was being passed in this format from the HTML form,

Description=&ServiceType=INITIALIZE&SearchID=PANUNC

Once I commented out the line setting the contentType, the servlet was happy with a simple request.getParameter("ServiceType").