ASP MVC Return SP result to View

64 views Asked by At

Using VS 2013 and writing my first ASP MVC app. I have a controller:

 // GET: CreateBundlesAndCartons
    public ActionResult CreateBandC(Int32 id)
    {
        string ReturnMessage;
        ReturnMessage = "";
        using (SqlConnection connection = new SqlConnection())
        {
            //string connectionStringName = this.DataWorkspace.CooperData.Details.Name;
            connection.ConnectionString =
                ConfigurationManager.ConnectionStrings["PSAContext"].ConnectionString;
            string procedure = "PSA.dbo.CreateBundlesAndCartons";
            using (SqlCommand command = new SqlCommand(procedure, connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 300;

                command.Parameters.Add(
                    new SqlParameter("@JobID", id));
                SqlParameter ErrorString = new SqlParameter("@ErrorString", ReturnMessage);
                ErrorString.Direction = ParameterDirection.Output;
                ErrorString.Size = 4000;
                command.Parameters.Add(ErrorString);

                connection.Open();
                command.ExecuteNonQuery();

                // Save Outout Param
                ReturnMessage = ErrorString.Value.ToString();

            }
        }
        return Content("You requested the to create bundles and cartons for job ID " + id.ToString() + "<br />Result: " + ReturnMessage + "<br /> ");
    }

I want to display the results to the user and them give them ability to return to the jobs view.

I tried this as my return value:

return Content("You requested the to create bundles and cartons for job ID " + id.ToString() + "
Result: " + ReturnMessage + "
Return to Jobs");

This displays the results and the link:

Result

But the link points to http://localhost:59971/Jobs/CreateBandC/~/Jobs/ instead of http://localhost:59971/Jobs/

How can I fix that?

Is there a better way to return the results?

I'm under some time pressure, so this approach would do for now, but I'd like to actually figure out how to return a more complex type and nicer view

Thanks

mark

1

There are 1 answers

3
beautifulcoder On

Looks like this requires database changes to fix the link. This is typically a result of poor design and tight coupling. So, go in the database and change the a tag in your stored procedure to get the desired result.