1 Replies - 2506 Views - Last Post: 18 September 2010 - 10:24 PM

#1 agent1   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 73
  • Joined: 09-July 10

MVC help needed

Posted 18 September 2010 - 09:37 PM

Hi there

I have a form that is wanting to post a comment, but when I click the button to post the form, it arrives at the action method with a null value for the parameter i specified.

I obviously want the string comment but also need the id of the event they have commented on. The id is getting lost somewhere as I did specifically add it to the values that are posted. Please have a look at my code below. Just for reference I have not altered global.asax at all or the routes there. Any ideas?

    <img src="<%=Model.Image %>" width="100" height="100" /><br /><br />
       
        <div class="display-field" style="font-weight: bold; font-size: x-large"><%= Html.Encode(Model.EventName) %></div><br />
        
     
        <div class="display-field"><%= Html.Encode(Model.Description) %></div><br />
        
        <div class="display-label">Address:</div>
        <div class="display-field"><%= Html.Encode(Model.Address) %></div><br />
        
        <div class="display-label">Date:</div>
        <div class="display-field"><%= Html.Encode(String.Format("{0:g}", Model.Date)) %></div><br />
        <%if (Model.Date < DateTime.Now)
          { %>
        <div class="display-label">AmountRaised:</div>
        <div class="display-field"><%= Html.Encode(String.Format("{0:F}", Model.AmountRaised))%><%} %></div><br />
        <%if(Request.IsAuthenticated)
          { %><%using (Html.BeginForm("AddComment", "Event", FormMethod.Post, new {id = Model.EventId }))
                { %>
              Add a comment:<br />
              <textarea name="comment" cols="50%" rows="2"></textarea><br />
              <button type="submit">Add comment</button><br />
              Please note that comments will be filtered before they are added
              <br />
              <br />
              
        
        <%} %>
       
        <%} %>
     </div>
        
   
    <p>
        <%if(Request.IsAuthenticated && User.IsInRole("Admin")){ %>
        <%= Html.ActionLink("Edit Event", "Edit", new { id=Model.EventId }) %> |
        <%} %>
        
        <%= Html.ActionLink("Back to List", "Index") %>
    </p>


Is This A Good Question/Topic? 0
  • +

Replies To: MVC help needed

#2 agent1   User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 73
  • Joined: 09-July 10

Re: MVC help needed

Posted 18 September 2010 - 10:24 PM

I have sorted my problem using a hidden field instead of form parameters

  <%using(Html.BeginForm("AddComment","Event",FormMethod.Post)){ %>
              Add a comment:<br />
           <textarea name="comment" cols="50%" rows="2"></textarea><br />
           <%=Html.HiddenFor(model => model.EventId) %>
              <button type="submit">Add comment</button><br />
              Please note that comments will be filtered before they are added
              <br />
              <br />

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1