0
var STVal = "247";
var Name = "abc";
var Cat = "general";       
var temp = '@string.Format("{0}-{1}-{2}", Cat, Name, STVal);'

alert(temp);

STVal, Name, Cat are my JavaScript variables and I want to format the string and to pass these variables in Razor View.

1

2 Answers 2

0

Not exactly what you are looking for but I use this

var temp = "CAT-NAME-STVAL".replace('CAT',Cat).replace('NAME',Name).replace('STVAL',STVal);
Sign up to request clarification or add additional context in comments.

Comments

0

Create a Ajax call to a controller function with your parameter individually like

$.ajax({  
  type: "POST",  
  contentType: "application/json; charset=utf-8",  
  url: "Controller/ActionMethod",  
  data: "{ STVal: '247', Name : 'abc', Cat : 'general' }",  
  dataType: "json",  
  success: function(response) { alert("item added"); },  
  error: function(xhr, ajaxOptions, thrownError) { alert(xhr.responseText); }

});

Receive the values in the Action Method and pass to a view like,

[HttpPost]
public ActionResult ActionMethod(string STVal, string Name, string Cat )
{
   // your code
   return view();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.