Note that there are some explanatory texts on larger screens.

plurals
  1. POrazor mvc4 and c# codebehind
    primarykey
    data
    text
    <p>Alright, so I have just started with razor mvc4 and I have a little experience with c#. I am currently making a website on which there is a button. my html follows: </p> <pre><code>&lt;button onclick ="vote1_click" id="VoteButton" value="Vote"&gt;Vote&lt;/button&gt; </code></pre> <p>this is in a .cshtml view</p> <p>I then have a class to handle the vote1_click event. It is in c# and follows:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MvcApplication1 { public class voting { public void vote1_click(object sender, EventArgs e) { } } } </code></pre> <p>I believe that my issue is a fundamental understanding of the razor structure, but could not figure it out on my own. </p> <p>Any help at all is appreciated, and I will try to not feel too stupid when the answer is simple.</p> <p>Thanks!</p> <p><strong>EDIT:</strong></p> <p>I have been getting an issue where the Add(string name) gives me an error of "not all code paths return a value"</p> <p>here is the rest of my code as requested:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Data.SqlClient; namespace WAgermanClub.Controllers { public class HomeController : Controller { [HttpPost] public ActionResult Add(string vote) { SqlConnection vote1connection = new SqlConnection("user id=userid;" + "password=validpassword;server=o5z5dpwpzi.database.windows.net;" + "Trusted_Connection=yes;" + "database=wagermanclub_votes; " + "connection timeout=30"); try { vote1connection.Open(); } catch (Exception g) { Console.WriteLine(g.ToString()); } try { SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand("select * from table", vote1connection); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { Console.WriteLine(myReader["Vote1"].ToString()); } } catch (Exception i) { Console.WriteLine(i.ToString()); } SqlCommand vote1command = new SqlCommand("INSERT INTO table (Column1, Vote1) " + "Values (1, 'Vote1' + 1)", vote1connection); vote1command.ExecuteNonQuery(); try { vote1connection.Close(); } catch (Exception h) { Console.WriteLine(h.ToString()); } } } </code></pre> <p>}</p> <p>And here is my HTML:</p> <pre><code>@{ ViewBag.Title = "Ideas"; } @section featured { &lt;section class="featured"&gt; &lt;div class="content-wrapper"&gt; &lt;hgroup class="title"&gt; &lt;h1&gt;@ViewBag.Title.&lt;/h1&gt; &lt;h2&gt;@ViewBag.Message&lt;/h2&gt; &lt;/hgroup&gt; &lt;p&gt; &lt;/p&gt; &lt;/div&gt; &lt;/section&gt; } &lt;body&gt; &lt;div style="border: solid; max-width: 300px; margin-left: auto; margin-right: auto"&gt; @using(Html.BeginForm()) { &lt;input type="submit" value="Vote"/&gt; } &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload